首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >PHP exec()在使用nohup时导致连接超时

PHP exec()在使用nohup时导致连接超时
EN

Stack Overflow用户
提问于 2020-11-25 01:09:33
回答 1查看 130关注 0票数 1

我有一个类使用PHP中的exec()函数执行python脚本。它给了我一个超时,即使我使用nohup在后台运行。

服务器运行在4GB内存上,是一个带有centOS 8的LXC容器,Web是nginx。

有什么想法吗?

代码语言:javascript
复制
<?php

class Deployment {

  private $clusterName;
  private $vendor;
  private $nodeIP;
  private $password;
  private $cmd;

  public function task($clusterName, $vendor, $nodeIP, $password) {

    $this->cmd = escapeshellcmd('python3 /usr/share/nginx/python/script.py --ip '.$nodeIP.' --password '.$password);

    // Execute Job here
    exec($this->cmd);
  }

  // Method used to execute the python engine
  private function exec($cmd = null){
     if(!$cmd){
         throw new Exception("No command given");
         die('No command given');
     }
     shell_exec("/usr/bin/nohup ".$cmd." > /dev/null 2>&1 &");
  }
}

我正在犯的错误:

代码语言:javascript
复制
2020/11/25 01:00:26 [error] 109#0: *5 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 192.168.10.225, server: _, request: "POST /dev/html/deploy.php HTTP/1.1", upstream: "fastcgi://unix:/run/php-fpm/www.sock", host: "172.16.10.202", referrer: "http://172.16.10.202/dev/html/deploy.php"
EN

回答 1

Stack Overflow用户

发布于 2020-11-25 06:52:50

问题是,我将我的私有函数重命名为exec(),而不考虑这个实际内置的PHP函数。

这是我更改的代码的一部分:

代码语言:javascript
复制
// Execute Job here
    $this->execTask($this->cmd);
  }

  // Method used to execute the python back-end engine
  private function execTask($cmd = null){
     if(!$cmd){
         throw new Exception("No command given");
         die('No command given');
     }
     shell_exec("/usr/bin/nohup ".$cmd." > /dev/null 2>&1 &");
  }
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64997134

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档