Hướng dẫn php exec in background

I am attempting to launch sar and have it run forever via a php script. But for whatever reason it never actually launches. I have tried the following:

exec['sar -u 1 > /home/foo/foo.txt &'];
exec['sar -o /home/foo/foo -u 1 > /dev/null 2>&1 &'];  

However it never launches sar. If I just use:

exec['sar -u 1']

It works but it just hangs the php script. My understanding that if a program is started with exec function, in order for it to continue running in the background, the output of the program must be redirected to a file or another output stream.

asked Jul 6, 2015 at 20:07

2

I will assume your running this on a *nix platform. To get php to run something in the background and not wait for the process to finish I would recommend 2 things: First use nohup and also redirect the output of the command to /dev/null [trash].

Example:

Chủ Đề