Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/238.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php proc_open-将进程句柄保存到文件并检索它_Php_Filehandle_Proc Open - Fatal编程技术网

Php proc_open-将进程句柄保存到文件并检索它

Php proc_open-将进程句柄保存到文件并检索它,php,filehandle,proc-open,Php,Filehandle,Proc Open,我使用以下代码打开proc_open进程,并将句柄和管道保存到文件中: $command = "COMMAND_TO_EXECUTE"; $descriptors = array( 0 => array("pipe", "r"), // stdin is a pipe that the child will read from 1 => array("pipe", "w"), // stdout is a pipe that the

我使用以下代码打开proc_open进程,并将句柄和管道保存到文件中:

    $command = "COMMAND_TO_EXECUTE";

    $descriptors = array(
        0 => array("pipe", "r"), // stdin is a pipe that the child will read from
        1 => array("pipe", "w"), // stdout is a pipe that the child will write to
        2 => array("file", "error-output.txt", "a")  // stderr is a file to write to
    );


    $pipes = array();

    $processHandle = proc_open($command, $descriptors, $pipes);

    if (is_resource($processHandle)) {     

        $processToSave = array(
            "process" => $processHandle,
            "pipes" => $pipes
        );

        file_put_contents("myfile.bin", serialize($processToSave) );        

    }
在第二个时刻,我需要从文件中检索这个文件句柄,我使用了以下代码:

$processArray = unserialize(file_get_contents("myfile.bin"));  
$processHandle = $processArray["process"];
$pipes = $processArray["pipes"];
但当我从文件中检索后打印$processHandle和$pipes的var_转储时,我会得到整数而不是资源或进程,但为什么呢

 var_dump($processHandle) ->  int(0)
 var_dump($pipes) - > array(2) { int(0), int(0) }
当然,在这一点上,如果我试图关闭管道,我将得到一个错误,预期的资源,给定的整数

我怎样才能让它工作?(注意:这是我正在寻找的解决方案)

但是,或者,我也可以得到进程的pid,然后使用这个pid来停止或终止进程,或者对进程执行任何其他操作,但是管道呢? 如何读取/写入或保存进程中的错误


谢谢

我自己找到了解决方案,不可能序列化资源,当脚本完成后,这些资源处理程序是免费的

解决方案是创建一个监听端口的守护进程,该端口在请求时启动并停止进程。由于进程始终在运行,因此它可以维护处理程序进程的列表,并在请求时停止