doupu1957 2015-07-08 10:31
浏览 196
已采纳

从PHP执行多个exec()

Situation:

I have a PHP application where I need to get some output from exec() commands. exec() commands are used on different locations throughout the application.

When a user opens multiple pages in the same browser, the exec() commands are allways executed sequentially; If a user opens a second page, the second page waits for the exec() command of the first page to finish, before executing. If I open a second page in a different browser, or in incognito, this problem does not occur.

Example test code:
$exec = "notepad.exe"
$data = shell_exec($exec);
echo $data;

When running this code in the browser, the browser waits for the notepad process to close. When running the script a second time simultaniously, the second notepad process is only started when the first one is closed, unless it's ran from a different browser.

Question: How can I run multiple exec() commands simultaneously from the same browser (in different tabs) while still beeing able to catch the output.

Tested on Apache 2.4 running PHP 5.4.7

  • 写回答

1条回答 默认 最新

  • duanjie2940 2015-07-08 14:05
    关注

    The issue was a combination with the use of sessions as described here: https://bugs.php.net/bug.php?id=44942

    Solution: While using sessions, we need to call session_write_close(); before running any exec() command.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题