kill cron

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, ...


Go Back   Usenet Forums > Web Server and Related Forums > Apache Web Server

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 10-27-2007
Séverin Richard
 
Posts: n/a
Default kill cron

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.
  #2 (permalink)  
Old 10-27-2007
Rik Wasmus
 
Posts: n/a
Default Re: kill cron

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
  #3 (permalink)  
Old 10-28-2007
shimmyshack
 
Posts: n/a
Default Re: kill cron

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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 01:46 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0