[UPHPU] Forking A Script

John David Anderson uphpu at johndavidanderson.net
Mon Jul 23 09:25:44 MDT 2007


On Jul 23, 2007, at 9:20 AM, Ken Snyder wrote:

> I need some type of script forking and I'm wondering if there is a  
> good way in PHP.
>
> Here is the situation: I have a script where a user picks some  
> options and a large report file is generated and emailed.  The  
> report will take several minutes to compile and I'd like to allow  
> the user to continue using the site.  So basically, I'm thinking  
> that at the end of the script I want to spawn off the report script  
> and return some html to the user so the user doesn't have to wait  
> for the report.
>
> I've considered work arounds such as cron batching and AJAX, but I  
> keep thinking there has to be a way to do it in PHP.  I've looked  
> at starting the report script with a shell command, but it seems  
> PHP waits for a return value.

You may not need to fork. Try appending an ampersand to the end of  
the command:

$ php doReportScript.php &

That'll run the process in the background (that way PHP won't wait  
for a return).

-- John


More information about the UPHPU mailing list