1

I want my php file to run in background. When I googled, I found that exec() is used to run in background. I am using a CentOS server. So, in order to use exec, what are all the basic things I should install? I don't even know how to run in terminal. What steps should I follow to run a php script in background using exec()?

I found this example on Google, but I don't know what to use in $cmd.

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

1 Answer 1

1

You can use nohup in your terminal:

nohup php my-file.php

Your PHP script will keep running even after you logout.

The other option is screen.

screen -A -m -d -S whatever ./phplauncher.sh
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.