Executing a shell script in background with php

前端 未结 2 1734
[愿得一人]
[愿得一人] 2021-02-06 10:26

I need to execute a shell script. The catch is I want to do this

$Command = \"nohup cvlc input --sout \'#transcode {vcodec=h264,acodec=mp3,samplerate=44100}:std{         


        
2条回答
  •  南旧
    南旧 (楼主)
    2021-02-06 10:52

    You can try running your command in background using a function like this one:

    function exec_bg($cmd) { 
        if (substr(php_uname(), 0, 7) == "Windows"){ 
            pclose(popen("start /B ". $cmd, "r"));  
        } 
        else { 
            exec($cmd . " > /dev/null &");   
        }
    }
    

    This makes your shell command runs, but the php flow continues.

提交回复
热议问题