jagat_21 — 2009-01-09T09:04:54-05:00 — #1
Currently We have scheduled No. Of Cron Jobs which will be executed As per the schedule time.
Using PHP Can We execute the cron job Manually ?
As per my experience, we can directly execute the PHP Script that we have setup in the cron job.
But is it possible to execute the cron job manully using the linux command that we can pass to php's exec() function ?
anthonysterling — 2009-01-09T09:06:09-05:00 — #2
execute the cron job manully using the linux command that we can pass to php's exec() function ?
It sounds like you already have your solution.
jagat_21 — 2009-01-09T09:14:32-05:00 — #3
But i want to know, how can we call cron job command using php's exec() function ?
Each cron job will take more than 15 hours to complete the process. So If i will allow the user to run cron job script through a external url there will be problem related to connection and all.
If the script is terminated then the execution for rest of the process will not be completed.
I have no. of stored procedures that will be called one after another in the php script. So let us assume that if currently user has started cron job and one stored procedure execution is in process at that time if the connection is lost then rest of the stored procedures mentioned in the php script will not be called.
anthonysterling — 2009-01-09T09:26:17-05:00 — #4
Why not create a table in a RDBMS of your choosing to store completed / pending runs?
You could create a PHP script to create a pending entry in this table, then increase your current CRON frequency to check this table and decide whether or not to run.
jagat_21 — 2009-01-09T10:00:24-05:00 — #5
Yes, i have already implemented that thing. And i am tracking the scheduled cronjob status in that way. But the thing is that now we have user who will be executing the script.
For example, if user has started the cron job script manually from external URL. And after some time if user closes the browser intentionally or unintentionally or system is switched off or anything from client side then the execution of rest of the script will be stopped.
anthonysterling — 2009-01-09T10:12:23-05:00 — #6
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'.
crmalibu — 2009-01-09T10:53:23-05:00 — #7
execute the php binary from a shell
/usr/bin/php /path/to/script.php > /dev/null &
jagat_21 — 2009-01-09T13:00:01-05:00 — #8
Can I call the above mentioned command using php's exec() function ?
Because the cron script will be executed by the user. And after calling the script if user closes the browser than also i want the procees to be continued.