Reputation: 58863
How can I spawn a process in a PHP page in order to start a program that survives the execution time of the request?
In other words, I want the page to have a normal lifetime (few milliseconds) but launch a program that keeps running on the server. Thanks
Upvotes: 13
Views: 10101
Reputation: 32701
Use this code:
<?php exec('nohup /usr/bin/my-command > /dev/null 2>&1 &'); ?>
This forks the sub-process into the background and writes all of the output into /dev/null
. That way PHP continues executing the script as if there won't be any output it has to wait for.
Upvotes: 21
Reputation: 1306
I would suggest you to use CRON if you need to start a process on a time basis.
Upvotes: -1