将php exec存储在会话变量中 [英] Store php exec in a session variable
问题描述
$ b
例如:
index.php
<?php exec ,$ arrat,$ _SESSION ['output']); ?>
follow.php
< php echo $ _SESSION ['output']); ?>
所以,当我运行index.php时,我可以关闭页面,导航到follow.php,
不,因为 exec
等待生成的进程在返回之前终止。但应该可以使用 proc_open
,因为该函数将生成的进程的输出作为流提供,不等待它终止。因此,在布朗条件下,您可以这样做:
- 使用
proc_open
并将其输出重定向到管道。 - 使用
stream_select
在某种循环中查看是否有输出要读; - 每当读取输出时,调用
session_start
,将其写入会话变量,调用session_write_close
。这是标准的会话锁舞蹈,允许您的脚本更新会话数据,而无需在整个时间内对其进行锁定。
Is is possible to store an exec' output into a session variable while its running to see it's current progress?
example:
index.php
<?php exec ("very large command to execute", $arrat, $_SESSION['output']); ?>
follow.php
<php echo $_SESSION['output']); ?>
So, when i run index.php i could close the page and navigate to follow.php and follow the output of the command live everytime i refresh the page.
No, because exec
waits for the spawned process to terminate before it returns. But it should be possible to do with proc_open
because that function provides the outputs of the spawned process as streams and does not wait for it to terminate. So in broard terms you could do this:
- Use
proc_open
to spawn a process and redirect its output to pipes. - Use
stream_select
inside some kind of loop to see if there is output to read; read it with the appropriate stream functions when there is. - Whenever output is read, call
session_start
, write it to a session variable and callsession_write_close
. This is the standard "session lock dance" that allows your script to update session data without holding a lock on them the whole time.
这篇关于将php exec存储在会话变量中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!