Continue execution after calling php passthru() function

╄→гoц情女王★ 提交于 2019-12-08 06:42:52

问题


When using php passthru() function, default is to stay until the external script execution ends.

PHP manual says ::::: "If a program is started with this function, in order for it to continue running in the background, the output of the program must be redirected to a file or another output stream. Failing to do so will cause PHP to hang until the execution of the program ends." - http://php.net/manual/en/function.passthru.php

I want to collect external script data for specific time e.g. for 30 seconds, and after that continue the php script execution. Any ideas how to do that?

My current code is:

    ob_start();
    passthru("/home/somefolder/somefolder2/program $pic1 $pic2");
    $details = ob_get_contents();
    ob_end_clean();

problem in above code is - sometimes "program" script keeps executing for a while, but i don't want to let the user to hang-on more than 30 seconds on this process.

I thought about redirecting the output to a file and read it after 30 seconds(according to the manual). But i don't know how redirect the output to a file.


回答1:


"/home/somefolder/somefolder2/program $pic1 $pic2 > /path/to/your/file 2>&1"

And if you want it run in the background, add & at the end.

"/home/somefolder/somefolder2/program $pic1 $pic2 > /path/to/your/file 2>&1 &"


来源:https://stackoverflow.com/questions/10798070/continue-execution-after-calling-php-passthru-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!