Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

execute bash script from php without waiting

Tags:

bash

php

I execute a bash script from php with shell_exec. But the php script waits until the shell script is finished.

Can I somehow call the bash script without waiting. Both:

exec
shell_exec

are waiting until the bash script is finished. I'm running linux btw.

like image 845
mjspier Avatar asked Mar 24 '11 14:03

mjspier


2 Answers

This has to work:

exec('/your/command /dev/null 2>/dev/null &');

like image 59
ChrisH Avatar answered Sep 30 '22 11:09

ChrisH


when calling your bash script append & so it will run in the background that's the easiest way if you don't need any output

shell_exec("/bin/bash /path/to/script.sh &"); 
like image 25
sharpner Avatar answered Sep 30 '22 11:09

sharpner