Re: asynchronous PHP



Lawrence Krubner escribió:
The server I'm working on right now allows PHP scripts to run for 300 seconds. I need to get around that. I'm writing a script that pings the Google Ajax API. The script is called as a cron job. It needs to make over 100,000 queries against Google.

I thought maybe I could get around the time limit by having the first script call other scripts, like this:

Normally, you can just increase the limit yourself, either in your custom config file on in code itself:

ini_set('max_execution_time', 86400); // 1 day in seconds

However, I remember having read somewhere that the command line SAPI defaults to "unlimited". Most of the time, there's no need to run cron jobs through the web server.

shell_exec("callGoogle1.php");
shell_exec("callGoogle2.php");
shell_exec("callGoogle3.php");
shell_exec("callGoogle4.php");
shell_exec("callGoogle5.php");


But the first PHP scripts waits for shell_exec() to return before making the next call. So how do I break out of the procedural, step-by-step approach that PHP takes? Is there a correct way to do this?

You can probably use some Unix fancy stuff, like:

shell_exec("./callGoogle1.php &");

Or maybe:

shell_exec("nohup ./callGoogle1.php &");


Have a look at this user note:

http://es.php.net/manual/en/function.set-time-limit.php#53564






--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://bits.demogracia.com
-- Mi web de humor al baño María: http://www.demogracia.com
--
.



Relevant Pages

  • rlogin via expect mysteriously aborts when run from cron
    ... I'm not sure whether this is a problem related to shell, ... I have an application which, at some point, executes a zsh script. ... When investigating the output which was sent to me from the cron job ... I had one case where even a command ...
    (comp.lang.tcl)
  • Re: How can I run cron job at 12o clock every night on my RH Linux machine?
    ... > How can I run cron job in Linux, I need to run some job automatically ... > every night at 12'o clock on my RH Linux machine. ... These four commands I need to place in that script. ...
    (comp.os.linux.misc)
  • Re: Cron jobs run out of memory?
    ... > (the script is attached to this e-mail). ... > cron job has failed, but running the program manually worked fine: ... -/+ buffers/cache: 169532 346776 ... Swap: 497968 274256 223712 ...
    (Debian-User)
  • Re: CRON or HTTP?
    ... or as an Apache module, there will be more information in $_SERVER. ... a script can be run from BOTH a cron job and a HTTP request: ...
    (comp.lang.php)
  • Re: script doesnt work when run as cron job
    ... >It should be mailed to you (or root, or whoevers' cron job it is). ... Earlier you posted this bit of script: ... >and this extract from the log files: ... Attempting to start rsync ...
    (comp.unix.shell)