【问题标题】:run php script in background centos server在后台centos服务器中运行php脚本
【发布时间】:2017-12-27 13:42:15
【问题描述】:

我希望我的 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 &");   
    } 
} 

【问题讨论】:

    标签: php mysql background centos exec


    【解决方案1】:

    您可以在终端中使用 nohup:

    nohup php my-file.php
    

    即使在您注销后,您的 PHP 脚本也会继续运行。

    另一个选项是screen

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

    【讨论】:

      猜你喜欢
      • 2023-03-19
      • 1970-01-01
      • 2021-07-06
      • 2011-05-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多