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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
paosav
Forum Newbie
Posts: 1
Joined: Mon May 24, 2010 9:04 am

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

Post 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
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

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

Post 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.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Post Reply