将php exec存储在会话变量中 [英] Store php exec in a session variable

查看:266
本文介绍了将php exec存储在会话变量中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

$ p
$ b

例如:



index.php



<?php exec ,$ arrat,$ _SESSION ['output']); ?>



follow.php



 < php echo $ _SESSION ['output']); ?> 

所以,当我运行index.php时,我可以关闭页面,导航到follow.php,

解决方案

不,因为 exec 等待生成的进程在返回之前终止。但应该可以使用 proc_open ,因为该函数将生成的进程的输出作为流提供,不等待它终止。因此,在布朗条件下,您可以这样做:


  1. 使用 proc_open 并将其输出重定向到管道。

  2. 使用 stream_select 在某种循环中查看是否有输出要读;

  3. 每当读取输出时,调用 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:

  1. Use proc_open to spawn a process and redirect its output to pipes.
  2. 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.
  3. Whenever output is read, call session_start, write it to a session variable and call session_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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆