在后台centos服务器中运行php脚本

问题描述 投票:1回答:1

我希望我的php文件在后台运行。当我用Google搜索时,我发现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 &");   
    } 
} 
php mysql background centos exec
1个回答
1
投票

您可以在终端中使用nohup:

nohup php my-file.php

注销后,您的PHP脚本将继续运行。

另一种选择是screen

screen -A -m -d -S whatever ./phplauncher.sh
© www.soinside.com 2019 - 2024. All rights reserved.