Re: PHP + Cron jobs

From: Date: Mon, 29 Sep 2008 15:59:59 +0000
Subject: Re: PHP + Cron jobs
References: 1 2 3 4 5 6 7  Groups: php.general 
Request: Send a blank email to php-general+get-281106@lists.php.net to get a copy of this message
Shawn McKenzie wrote:
Shawn McKenzie wrote:
Waynn Lue wrote:
Yup, you're completely right. I checked the cronjob and got this: PHP 5.2.6 (cgi) (built: Aug 11 2008 13:39:32) Copyright (c) 1997-2008 The PHP Group Zend Engine v2.2.0, Copyright (c) 1998-2008 Zend Technologies with Advanced PHP Debugger (APD) v0.9, , by George Schlossnagle Turns out there's /usr/bin/php, which is the cgi version, and /usr/local/bin/php, which is the cli version. So I see three possiblities. 1. Change the shebang on the php script itself, 2. change the crontab to reflect to path I care about, or 3. replace /usr/bin/php. I'd prefer the 3rd, but does that cause problems for me in my actual web pages? Thanks, Waynn
Depends upon whether your webserver is using the PHP CGI binary or the apache module. I thought common convention was that the CGI was named php-cgi? I would rename '/usr/bin/php' to '/usr/bin/php-cgi', grep your web server conf file(s) for /usr/bin/php and if found then change it to /usr/bin/php-cgi. -Shawn
Along with that, I would opt for always using the full path in the cron job. -Shawn
see I don't use cron; I run small scripts from the command line that fork then run forever on a while loop with a sleep.. so: worker.php <?php include '/path/to/maininclude.php'; $pid=pcntl_fork(); if(!$pid) { while(1) {
    $work = new work_object;
    if( $job = $work-getJobs->('thisjob') ) {
      // i have something to do, and doing it here
    } else {
      sleep(10);
    }
} } else { echo "\ndaemon launcher done id $pid\n"; } ?> or you can run say 10 versions at the same time for things where multi-process helps (scrapers, whois checks etc) controller.php <?php include '/path/to/maininclude.php'; for($icount=0;$icount<11;$icount++) { include './worker.php'; //spawn 10 workers } ?> just my preference :)

« previous php.general (#281106) next »