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

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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-13 12:05:38
Original
1119 people have browsed it

复制代码 代码如下:


$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 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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template