Page 1 of 1

How to launch a php from inside another, not waiting for it

Posted: Mon May 24, 2010 9:07 am
by paosav
Hi all.

I need to launch a php update script
from within another one (main)

but I need the main.php not to stop waiting for the update.php to finish its task,
so I can't use "INCLUDE" command.

Any suggestion?

Paolo

Re: How to launch a php from inside another, not waiting for

Posted: Mon May 24, 2010 9:37 am
by AbraCadaver
It depends upon what you need from the script and what platform you're on. On *nix using exec('/path/to/php /path/to/file/file.php &') should launch it in the background. If you need the output or errors then redirect stdout and stderr to a log file. Or you can use popen(). If you're on windows you can use popen('start c:\path\to\php.exe c:\path\to\file.php') I think.

Another alternative would be to add this as a 'job' to a database table and then have either cron or task scheduler check the database every minute or hour or whatever and if there is a job run the PHP script.