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

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

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

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));
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn