我有一些php代码在后台执行另一个php文件,如下所示。问题是http进程在执行完成之前不会继续。如果有人能帮到我,我会非常感激。
//Process firstsearch/getInfo.php in the background
$file = "/home/cyber/public_html/firstsearch/getInfo.php";
//set Options array to be used for command execution
$options=array();
$option['sleep-after-destroy']=0;
$option['sleep-after-create']=0;
$option['age-max']=40;
$option['dir-run']=dirname(__FILE__);
$option['step-sleep']=1;
$option['workers-max']=(int)file_get_contents($file);
$option['destroy-forcefull']=1;
$workers=array();
//description pipe declaration
$desc = array(
0 => array('pipe', 'r'),
1 => array('pipe', 'w'),
2 => array('file', 'run_errors.txt', 'a')
);
//generate random number for file id
$i=rand();
//command to run the script
$runcommand='php '.$file.' '.$i.' '.$child_time_limit.' > '.$option["dir-run"].'/'.$i.'.normal.log';
//workers array of processes
$workers[$i]=array(
'desc' => array(
0 => array("pipe", "r"),
1 => array("pipe", "w"),
2 => array("file", $i.'.error.log', "a")
),
'pipes' => null,
'link' => null,
'start-time' => mktime()
);
//execution command
$workers[$i]['link']=proc_open(
$runcommand,
array(), //$workers[$i]['desc'],
$workers[$i]['pipes'],
$option['dir-run']
);
//halt for number of secs depending on the set option before proceeding to the next line of code
sleep($option['sleep-after-create']);
//get status of currently executed script
$proc_status=proc_get_status($workers[$i]['link']);
//get process id of the process
$pid=trim(exec('ps h -o pid --ppid '.$proc_status['pid']));
//manually kill the process to avoid waiting for the execution to completed before the http process continues
exec('kill -s 9 '.$proc_status['pid']);
//close current process
proc_close($workers[$i]['link']);
//unregister workers array
unset($workers[$i]);
//End of Process firstsearch/getInfo.php in the background