我有一个类使用PHP中的exec()函数执行python脚本。它给了我一个超时,即使我使用nohup在后台运行。
服务器运行在4GB内存上,是一个带有centOS 8的LXC容器,Web是nginx。
有什么想法吗?
<?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 &");
}
}我正在犯的错误:
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"发布于 2020-11-25 06:52:50
问题是,我将我的私有函数重命名为exec(),而不考虑这个实际内置的PHP函数。
这是我更改的代码的一部分:
// 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 &");
}https://stackoverflow.com/questions/64997134
复制相似问题