on 1/17/01 10:12 AM, Chris Lee at [EMAIL PROTECTED] wrote:
>> There are occasions when I'd like to execute some long-running task
>> in the background, in response to some user action. It seems that
> Im nearly posative this isnt what your looking for, but I thought I would
> see if maybe it was :)
> compile php as a cgi so you can run it from the command prompt. then just
> run the php file from the command prompt through exec ()
> <?
> exec("php -q somephpfile.php &");
> ?>
If you want the thing to always complete then you'll need to nohup the
exec call. Otherwise, the "php -q" would be a child process of the php
module and will be killed when the web page script quits (assuming you
compiled PHP as a module (shared or otherwise)). That kill would occur when
the it finishes outputting the page or the browser has closed the connection
(moves onto another page).
Another note is I believe exec() returns the last line of the output of
the command. This means that you'll see the browser stuck on the last
flush() before function handle_some_action() until you reach the timeout
specified in php.ini (usually 30 seconds) as the php module will need to
wait for the command to complete before it returns a line. popen() would
also do this (I believe the pipe blocks until the output is filled). So for
this to work you've got to set it so that it returns immediately...
something like..
"nohup php -q somephpfile.php >&/dev/null &"
(or somesuch).
>> In the cases I'd like to do this, I can manage synchronization
>> externally...
>> (i.e., implement join by waiting for a /tmp file to appear or
>> something),
>> so I'm not asking for a join, or any sychronization facilities.
I'm not too certain what is meant by this, so I don't know if what I was
any help. :-)
Note that the "somephpfile.php" does not need to have set_time_out(0)
because when php is run from the command line it will keep executing even
after the timer has expired. I don't know if this is a bug or a feature.
Take care,
terry
--
terry chay, Director of Engineering, <http://www.QIXO.com/>
QIXO /kick.so/ - Integrating Many Travel Web Sites Into One
W: 1.408.394-8102 F:1.408.516.9090 M: 1.408.314.0717
E-Mail: <mailto:[EMAIL PROTECTED]> ICQ: 16069322
PGP Fingerprint: 6DCF 1634 547C 935D 4912 2A44 A4A2 79AB DFFF F110
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]