-4

I have some data that are inserted to database after form submit. After they are inserted to databse I need to sed that data to email but I have to wait 5 minutes before I send them.

Is there anyway that I can wait for 5 minutes with, let say with sleep function. I do not want user to wait 5 minutes for script to be executed.

This is what I am thinking:

1) submit form and insert data to db

2) send inserted row id to some other script that runs somehow on server as process

3) after 5 minutes send email with script that is run as a process

4) if there is more then let say 50 ids on hold fire up new process and do steps from 3-4 again.

This is just what I am thinking.

I have no idea where to start.

Please give me some directions. I do not need redy to use solution.

I do not want to use cron job!!!

pregmatch
  • 2,629
  • 6
  • 31
  • 68
  • 1
    Why not use cron if it would work? – Grant Thomas May 01 '13 at 10:20
  • If you could explain why you need to wait 5 minutes, it might be easier for us to suggest a solution – Tim Fountain May 01 '13 at 10:21
  • I see you saying you don't want to use cron job, but wonder why. Otherwise you need to create a server process and set up a monitoring process to ensure the server process is running all the time. – Anigel May 01 '13 at 10:21
  • It does not matter why I want to wait for 5 minutes. I want to wait for an hour on 10 minutes. Time is irelevant here. – pregmatch May 01 '13 at 10:24
  • I do not have any code.I do not seek any code, I just need suggestion on how to do this with let say pseudo code if you will. – pregmatch May 01 '13 at 10:26

3 Answers3

1

The wrong answer in pseudo code is to

Put record in queue with timestamp eg a database
Write server process to monitor queue and see if 5 mins has passed
Send mail if 5 mins have passed.
Write monitoring system to monitor server process and ensure it is working.

The much better answer would be to use the linux at function if available or other pre-existing task scheduling system dependent on an unspecified platform. Scheduling tasks to occur at a certain time is exactly what you need to do and that is what these systems are designed to do.

Anigel
  • 3,435
  • 1
  • 17
  • 23
  • I was able to solve this with help of AT linux daemon: echo "wget http://domain/script.php?email=me@me.com" | at now + 5 min. – pregmatch May 06 '13 at 17:11
0

You can schedule tasks that runs after 5 minutes as follows...

On Windows:

Adding tasks to Windows scheduler with PHP

On Linux:

shell_exec("echo 'date > /some/dir/date.txt' | at now + 1 minute");

Community
  • 1
  • 1
Dharmesh Patel
  • 1,881
  • 1
  • 11
  • 12
-1

Best Way You can Insert Your Form Data With Time Field Which Will Keep The Record Of Inserted Time. On the otherside You create A PHP file with META refresh of 30 SEC Which Will Check All records Which have matured with time of 5 Mintues and do what you want to do and also mark the status for which action has been performed so that those records are not selected agian.