PHP-如何存储资源供以后使用
我想存储proc_exe中的资源以供以后使用。这样我就可以与开放进程进行通信。。。但它似乎无法存储在$\u会话中,有人知道如何存储它吗PHP-如何存储资源供以后使用,php,Php,我想存储proc_exe中的资源以供以后使用。这样我就可以与开放进程进行通信。。。但它似乎无法存储在$\u会话中,有人知道如何存储它吗 session_start(); if(is_resource($_SESSION['process'])) { echo "I was here"; proc_close($_SESSION['process']); } else { $descriptorspec = array( 0 => array("pipe", "r")
session_start();
if(is_resource($_SESSION['process']))
{
echo "I was here";
proc_close($_SESSION['process']);
}
else
{
$descriptorspec = 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", "/tmp/error-output.txt", "a") // stderr is a file to write to
);
$_SESSION['process'] = proc_open("myProgram", $descriptorspec, $p, null, null);
if(is_resource($_SESSION['process']))
{
echo "<pre>";
print_r($_SESSION); //Untill here everything of
echo "</pre>";
}
}
session_start();
if(是_资源($_会话['process']))
{
回声“我在这里”;
进程关闭($_会话['process']);
}
其他的
{
$descriptorspec=数组(
0=>array(“pipe”,“r”),//stdin是子级将从中读取的管道
1=>array(“pipe”,“w”),//stdout是子级将写入的管道
2=>array(“file”,“/tmp/error output.txt”,“a”)///stderr是一个要写入的文件
);
$\u SESSION['process']=proc\u open(“myProgram”,$descriptorspec,$p,null,null);
if(是_资源($_会话['process']))
{
回声“;
打印($_SESSION);//直到这里
回声“;
}
}
谢谢资源无法保存,它们特定于当前的PHP进程。是否有任何方法可以启动一个进程,然后在我需要时与之“交谈”?感谢进入WebSocket。使用ssh2函数也不可能?不可以。您只能保存普通数据:数字、字符串、数组和对象。与网络连接、进程、文件句柄等外部资源无关。