-->

调用PHP中继()函数后继续执行(Continue execution after calling

2019-09-17 14:22发布

当使用PHP中继()函数,默认是留到外部脚本执行结束。

PHP手册说:::::“如果一个程序开始使用此功能,以便它继续在后台运行,该程序的输出必须重定向到文件或其他输出流。如果不这样做会导致PHP挂起,直到该程序的执行结束。” - http://php.net/manual/en/function.passthru.php

我想收集特定的时间如外部脚本数据30秒,之后继续在PHP脚本执行。 任何想法如何做到这一点?

我当前的代码是:

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

在上面的代码中的问题是 - 有时是“程序”的剧本保留了一段时间执行,但我不想让用户挂在超过30秒的这个过程。

我想到的输出重定向到一个文件和30秒(根据说明书)后读取。 但我不知道如何将输出重定向到一个文件中。

Answer 1:

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

如果你希望它在后台运行,添加&结尾。

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


文章来源: Continue execution after calling php passthru() function