Home > php教程 > PHP源码 > body text

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

PHP中文网
Release: 2016-05-25 17:13:17
Original
1072 people have browsed it

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));
Copy after login
source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!