How can a PHP script start another PHP script, and then exit, leaving the other script running?
Also, is there any way for the 2nd script to inform the PHP script when it reaches a particular line?
How can a PHP script start another PHP script, and then exit, leaving the other script running?
Also, is there any way for the 2nd script to inform the PHP script when it reaches a particular line?
If you don't want to build the pcntl extension, then a good alternative is to use proc_open().
http://www.php.net/manual/en/function.proc-open.php
Use that together with stream_select() so your PHP process can sleep until something happens with the child process you created.
That will effectively create a process in the background, without blocking the parent PHP process. You PHP can read and write to STDIN, STDOUT, STDERR.
To make the browser complete loading (stop the load progress indicator) then you can use what Milan Babuškov mentioned.
The key to making the browser think the HTTP request is complete, is to send it the content length. To do this you can start buffering the request, then flush it after you send the Content-Length header.
eg:
Here's how to do it. You tell the browser to read in the first N characters of output and then close the connection, while your script keeps running until it's done.
Would
pcntl_fork()
do something similar to what you're ultimately trying to accomplish? http://www.php.net/manual/en/function.pcntl-fork.phpHere's a shot in the dark: you could try using php's OS execution functions with
&
.Additionally, if that doesn't work, you can try
Edit: nohup is a POSIX command to ignore the HUP (hangup) signal, enabling the command to keep running after the user who issues the command has logged out. The HUP (hangup) signal is by convention the way a terminal warns depending processes of logout.
You can effectively achieve this by forking and then calling
include
orrequire
.parent.php:
sleeper.php:
Output:
However, forking does not inherently allow any inter-process communication, so you'd have to find some other way to inform the parent that the child has reached the specific line, like you asked in the question.
You can create a request and close the connection right after it is done being written to.
Checkout the code in http://drupal.org/project/httprl as can do this (non-blocking request). I plan on pushing this lib to github once I get it more polished; something that can be ran outside of drupal. This should do what your looking for.