jcubic
jcubic

Reputation: 66488

How to execute shell command from php in background

How can I execute shell command in background using & at the end? I've try:

php -r "shell_exec('sleep 10 &');"

and

php -r "shell_exec('/bin/bash -c \"sleep 10 &\"');"

in both cases it pause for 10 seconds instead of just give the shell back and run sleep in background.

Upvotes: 1

Views: 116

Answers (1)

Daniele Pantaleone
Daniele Pantaleone

Reputation: 2723

You have to reroute the output somewhere. Try something like this:

php -r "shell_exec('sleep 10 > /dev/null &');"

Upvotes: 3

Related Questions