简体   繁体   中英

PHP spawn process

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

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.

如果您需要按时启动流程,我建议您使用CRON。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM