调用php passthru()函数后继续执行 [英] Continue execution after calling php passthru() function

查看:317
本文介绍了调用php passthru()函数后继续执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用php passthru()函数时,默认设置为保留,直到外部脚本执行结束.

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

PHP手册中的:::::如果使用此功能启动程序,则要使其在后台继续运行,必须将程序的输出重定向到文件或其他输出流.这样做将导致PHP挂起,直到程序执行结束." - http://php.net/manual/zh/function.passthru.php

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

我想收集特定时间的外部脚本数据,例如30秒,然后继续执行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?

我当前的代码是:

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

上述代码中的问题是-有时程序"脚本会持续执行一段时间,但我不想让用户在此过程中挂断超过30秒.

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.

我考虑过将输出重定向到文件并在30秒后读取(根据手册).但是我不知道如何将输出重定向到文件.

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.

推荐答案

"/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 &"

这篇关于调用php passthru()函数后继续执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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