Home  >  Article  >  php教程  >  PHP下利用shell后台运行PHP脚本,并获取该脚本的Process ID的代

PHP下利用shell后台运行PHP脚本,并获取该脚本的Process ID的代

WBOY
WBOYOriginal
2016-06-06 20:38:44837browse

PHP下利用shell后台运行PHP脚本,并获取该脚本的Process ID的代码,学习php的朋友可以参考下。

代码如下:
$command = '/usr/bin/php /pub/www/u111/job/Crondo/auto_collector.php &';
$process = proc_open($command, array(),$pipes);
$var = proc_get_status($process);
proc_close($process);

//pid就是进程ID,至于为什么要加1,我现在也没有搞懂,经过多次的测试,发现$var['pid']得到的ID比实际的少1
$pid = intval($var['pid'])+1;

//杀死进程
proc_close(proc_open('kill -9 '.$pid, array(), $pipes));
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn