我希望我的php文件在后台运行。
当我在谷歌上搜索时,我发现exec()是用来在后台运行的。我用的是CentOS服务器。
所以,为了使用exec,我应该安装哪些基本的东西?
我甚至不知道怎么在终点站跑。
使用exec()在后台运行php脚本应该遵循哪些步骤?
我在Google上找到了这个例子,但我不知道在$cmd中使用什么。

function execInBackground($cmd) {
    if (substr(php_uname(), 0, 7) == "Windows"){
        pclose(popen("start /B ". $cmd, "r"));
    }
    else {
        exec($cmd . " > /dev/null &");
    }
}

最佳答案

您可以在终端中使用nohup:

nohup php my-file.php

即使注销后,您的PHP脚本也将继续运行。
另一个选项是screen
screen -A -m -d -S whatever ./phplauncher.sh

10-07 19:22
查看更多