Home  >  Article  >  Backend Development  >  Under PHP, use the shell background to run the PHP script and obtain the code of the Process ID of the script_PHP Tutorial

Under PHP, use the shell background to run the PHP script and obtain the code of the Process ID of the script_PHP Tutorial

WBOY
WBOYOriginal
2016-07-21 15:24:461102browse

Copy the code The code is as follows:

$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 is the process ID. As for why it needs to be added by 1, I still don’t understand it. After many tests, I found that the ID obtained by $var['pid'] is 1 less than the actual one
$pid = intval($var['pid'])+1;

//Kill the process
proc_close(proc_open('kill -9 '.$pid, array(), $pipes));

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/324223.htmlTechArticleCopy the code as follows: $command = '/usr/bin/php /pub/www/u111/job/ Crondo/auto_collector.php $process = proc_open($command, array(),$pipes); $var = proc_get_status($process); pr...
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