5

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.

2 Answers 2

5

This has to work:

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

Sign up to request clarification or add additional context in comments.

1 Comment

ok almost the final solution was sh command > /dev/null 2>&1 & thanks for the input
1

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 &"); 

2 Comments

what exactly did not work? the running in the background? the script? maybe it is a permission problem
php was still waiting until the script was executed. "sh command > /dev/null 2>&1 &" did the trick though. thanks for your help :)

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.