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

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

$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));

分类:Other
  1. 还没有评论。
  1. No trackbacks yet.

发表评论

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 更改 )

Twitter picture

You are commenting using your Twitter account. Log Out / 更改 )

Facebook photo

You are commenting using your Facebook account. Log Out / 更改 )

Google+ photo

You are commenting using your Google+ account. Log Out / 更改 )

Connecting to %s

%d 博主赞过: