PHP: exec() doesn't run in the background even with “>/dev/null 2>&1 &”

前端 未结 7 1025
迷失自我
迷失自我 2021-01-04 10:59

I\'m calling this in my php script:

    exec(\"gutschein.php >/dev/null 2>&1 &\");

Calling the script (generates a pdf and s

7条回答
  •  旧巷少年郎
    2021-01-04 11:54

    Can you try one of the following 2 commands to run background jobs from PHP:

    $out = shell_exec('nohup /usr/bin/php /path/to/gutschein.php >/dev/null 2>&1 &');
    

    OR

    $pid = pclose(popen('/usr/bin/php gutschein.php', 'r'));
    

    It will execute the command in background and returns you the PID, which you can check using condition $pid > 0 to ensure it has worked.

提交回复
热议问题