2014-03-06 200 views
1

我想让我的php文件在后台运行。 当我GOOGLE时,我发现exec()用于在后台运行。我正在使用CentOS服务器。 因此,为了使用exec,我应该安装哪些基本的东西? 我甚至不知道如何在终端中运行。 我应该遵循什么步骤来使用exec()在后台运行php脚本?在后台运行php脚本centos server

我在Google上找到了这个例子,但我不知道在$cmd中使用什么。

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

回答

1

您可以在终端使用nohup的:

nohup php my-file.php 

你的PHP脚本将继续运行在注销后也。

其他选项是screen

screen -A -m -d -S whatever ./phplauncher.sh