0

我在 laravel 中创建了以下命令来检查另一个工匠命令是否仍在运行。如果我使用 artisan 通过命令行运行下面的代码运行良好但使用 crontjob 它返回空白输出。

class ProcessStarter extends Command
{
    protected $signature = 'process:start';
    
       
    public function __construct()
    {
        parent::__construct();
    }

    public function handle()
    {
        $output = shell_exec("ps -agfx | grep 'php artisan send:email 17 20220127 test1.67$' | grep -v grep | awk '{print $1}'");
        error_log("Command : ".$output."\n",3,'/var/www/html/log.txt');
    }
}

如果我将 handle() 代码放在普通的 php(checkProcess.php) 文件中并将其设置为通过 cronjob 运行,也会得到预期的结果。

checkProcess.php

$output = shell_exec("ps -agfx | grep 'php artisan send:email 17 20220127 test1.67$' | grep -v grep | awk '{print $1}'"); 
error_log("Core PHP: ".$output."\n",3,'/var/www/html/log.txt');

log.txt输出

核心 PHP:41287
命令:

以下是 crontab 条目。

*/1 * * * * (cd /var/www/html && php artisan schedule:run) >> /dev/null 2>&1
*/1 * * * * (cd /var/www/html && php checkProcess. php)

注意:在 nginx 上运行的 Laravel 应用程序

4

0 回答 0