php exec() background process issues

前端 未结 2 1629
南笙
南笙 2020-12-30 05:25

I\'m trying to process a file in the background with the following command, but it does nothing.

exec(\"php csv.php $file $user > /dev/null &\", $outp         


        
相关标签:
2条回答
  • 2020-12-30 05:40

    Have you considered using screen? You can start up a screen session that runs in a detached process. Output will go to the screen session, which you can reattach to in another terminal while it is still running.

    exec("screen -d -m -S my_php_session csv.php $file $user", $output);
    
    0 讨论(0)
  • 2020-12-30 05:48

    Note:

    If a program is started with this function, in order for it to continue running in the background, the output of the program must be redirected to a file or another output stream. Failing to do so will cause PHP to hang until the execution of the program ends.

    http://php.net/manual/en/function.exec.php

    so:

    exec("php csv.php $file $user > /dev/null &"); // no $output
    
    0 讨论(0)
提交回复
热议问题