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

从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.

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

报告相同问题?