Reputation: 672
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 &");
}
}
Upvotes: 1
Views: 958
Reputation: 4275
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
Upvotes: 1