Osa
Osa

Reputation: 1990

PHP exec with nohup

I currently use nohup to run a long php script and redirect the live results to a file using this command

nohup php long_file.php >logs 2>&1 &

so i just go and visit logs file continuously to see the results

Now i want to do the exact same thing using another php file to execute the above command
i tried the above command with php exec and the redirect output doesn't seem to be working,

I know i can just retrive the output using php and store it using any file write function but the thing is .. the output is too long thats why i keep it running on server's background

a similar question : Shell_exec php with nohup, but it had no answer

any solution ?

Upvotes: 0

Views: 3040

Answers (3)

Bas Peters
Bas Peters

Reputation: 1771

You are redirecting STDOUT to a file by using >

This will truncate the file each time the script is run. If two scripts simultaneously redirect their output to the same file, the one started last will truncate the output from the first script.

If you really want to properly append to a log file with multiple concurrent running scripts, consider using >> to avoid having the log file truncated.

Side effect however is that the log file never truncates and keeps expanding, so if the file gets really large you can consider including it in a logrotate scheme.

Upvotes: 0

nerkn
nerkn

Reputation: 1980

Please try with -q

nohup php -q long_file.php >logs 2>&1 &

http://ubuntuforums.org/showthread.php?t=977332

Upvotes: 1

hudolejev
hudolejev

Reputation: 6018

Did you try passthru instead of exec?

Upvotes: 0

Related Questions