0

linux下php在后台执行命令

Posted in PHP at 四月 29th, 2011 / No Comments »

启动命令后马上返回,得到此命令的pid:

exec("/opt/monitor.sh > /dev/null 2>&1 & echo $!", $output, $retval);

要把输出重定向到其它设备,如果有错误输出,也要重定向到其它设备。
“echo $!”不能少,否则exec会一直等待命令的执行后的返回值。

启动命令,命令发出exit指令后就返回:

exec("/opt/monitor.sh > /dev/null 2>&1", $output, $retval);

适用于脚本中有调用其它子命令,且脚本执行完后子命令不结束。此时$retval即为/opt/monitor.sh的exit值

http://blog.leezhong.com/tech/2010/12/05/php-async.html

http://zh-cn.w3support.net/index.php?db=so&id=1198052

Published in PHP
Tags: , ,

No Responses to “linux下php在后台执行命令”

Leave a Reply

请输入算式结果(看不清请点击图片)
(必须)