This is a discussion on kill cron within the Apache Web Server forums, part of the Web Server and Related Forums category; Hi all, How can i kill a cron process with a php script? My cron task starts evry 5 minutes, ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Hi all,
How can i kill a cron process with a php script? My cron task starts evry 5 minutes, but may work more than this time. (no timeout configured on my server for cron tasks (?). I guess if i can stop every process of this task before starting it again. my task looks like: usr/local/bin/php -q -f /home/mypass/cron.php then php script cron starts... THX for ,idears. |
|
|||
|
On Sat, 27 Oct 2007 13:19:43 +0200, Séverin Richard
<severin.richard@free.fr> wrote: > Hi all, > > How can i kill a cron process with a php script? > > My cron task starts evry 5 minutes, > but may work more than this time. (no timeout configured on my server > for cron tasks (?). > > > I guess if i can stop every process of this task before starting it > again. > > > my task looks like: > usr/local/bin/php -q -f /home/mypass/cron.php > > then php script cron starts... I'm not directly aware of a method, but another way would be: - either let the PHP script check the time itself (if it can take 5 minutes, usually a loop/while construct is involved somewhere, which would be a very handy place to let the script die if it takes to long). <?php $time = time(); .... while($data){ if((time()-$time) > 300) exit; //do some processing } - or let the PHP script set a flag in a file or database indicating it's busy, and let it remove it when it finishes. On a start, it would check wether another one was still busy and die() if another job was still running. -- Rik |
|
|||
|
On Oct 27, 10:35 pm, "Rik Wasmus" <u...@tfwasmus.enschedenet.nl>
wrote: > On Sat, 27 Oct 2007 13:19:43 +0200, Séverin Richard > > > > <severin.rich...@free.fr> wrote: > > Hi all, > > > How can i kill a cron process with a php script? > > > My cron task starts evry 5 minutes, > > but may work more than this time. (no timeout configured on my server > > for cron tasks (?). > > > I guess if i can stop every process of this task before starting it > > again. > > > my task looks like: > > usr/local/bin/php -q -f /home/mypass/cron.php > > > then php script cron starts... > > I'm not directly aware of a method, but another way would be: > - either let the PHP script check the time itself (if it can take 5 > minutes, usually a loop/while construct is involved somewhere, which would > be a very handy place to let the script die if it takes to long). > <?php > $time = time(); > ... > while($data){ > if((time()-$time) > 300) exit; > //do some processing > > } > > - or let the PHP script set a flag in a file or database indicating it's > busy, and let it remove it when it finishes. On a start, it would check > wether another one was still busy and die() if another job was still > running. > -- > Rik normally it doesnt mater how long a job runs for when using cron, it is just a way to start them off. This suggest some issue with your implementation - there are cron classes in a few of the larger open source projects around, i think wordpress has one. there might be some code you code reuse there if your project can allow this. what kind of jobs are we talking here, since php appears to have the rights to execute them are we talking image resizing etc... in this case Rik is right, why not just handle the jobs through a job handler which uses some logic (database + ps grepping and PID), so that the server gets round to doing them sequentially, and can also prioritise importnat jobs and jumpo them up the queue, no need for cron restarts. Also you dont have the problem of multiple intensive jobs tying up your CPU when they could have been "niced" and run sequentially. |
| Thread Tools | |
| Display Modes | |
|
|