The script the user is calling, should NOT be the script that process your job. It should only create an entry in your job table as pending.
It would essentially only consist of the following:-
* 0 = Requested / Pending
* 1 = Running
* 2 = Complete
* 3 = Cancelled
$sSQL = sprtinf("INSERT INTO table (user, requested, completed, status)VALUES('%s', %s, 0, 0);",
$rResult = mysql_query($sSQL);
You would then have a separate script that would determine how to proceed based on the data contained within the queue.
- Has a job ran in the x hours, if so cancel all current requests
- If no jobs scheduled and its been over x hours schedule a job and run it marking its status as 'running'.