制作2个文件
1.处理器.php
<?php
if($arc < 1) user_error('needs a argument');
$a=new FileProcessing($argv[1]);
$a->doProcessFile();
2.调用者.php
<?php
function process($path,$name){
$a = array();
$descriptorspec = array(
1 => array("file", "/tmp/$name-output.txt", "a"), // stdout is a pipe that the child will write to
2 => array("file", "/tmp/$name-error.txt", "a") // stderr is a file to write to
);
return proc_open(PHP_BINARY.' processor.php '.escapeshellarg($path), $descriptorspec, $a);
}
$proc1 = process($path1,'path1');
$proc2 = process($path2,'path2');
//now wait for them to complete
if(proc_close($proc1))user_error('proc1 returned non 0');
if(proc_close($proc2))user_error('proc2 returned non 0');
echo 'All done!!';
请务必阅读proc_open的文档以获取更多信息,还请注意,您需要在处理器中包含类(以及它需要的任何东西),因为它是一个新的 php 环境