HTTP process does not continue before the execution of PHP is completed -
i have php code executes php file in background shown below. problem http process not continue before execution completed. if out appreciate it.
//process firstsearch/getinfo.php in background $file = "/home/cyber/public_html/firstsearch/getinfo.php"; //set options array used 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 file id $i=rand(); //command run 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 number of secs depending on set option before proceeding next line of code sleep($option['sleep-after-create']); //get status of executed script $proc_status=proc_get_status($workers[$i]['link']); //get process id of process $pid=trim(exec('ps h -o pid --ppid '.$proc_status['pid'])); //manually kill process avoid waiting execution completed before 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 background
Comments
Post a Comment