0

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 ?

Community
  • 1
  • 1
Osa
  • 1,922
  • 7
  • 30
  • 51

3 Answers3

1

Please try with -q

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

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

nerkn
  • 1,867
  • 1
  • 20
  • 36
0

Did you try passthru instead of exec?

hudolejev
  • 5,846
  • 4
  • 22
  • 28
0

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.

Bas Peters
  • 1,751
  • 1
  • 11
  • 10