0

I am trying to run bgprocess.php in background and want to save output in backgroundOutput.php

exec("php bgprocess.php > backgroundOutput.php 2>&1 & echo $!", $commandOutput);

But its not showing any error on $commandOurput and not run bgprocess.php as well.

Its works : exec("php bgprocess.php", $commandOutput);

and also works from terminal command line.

tried following possible way to solve issue by reference :

Bhavesh Chauhan
  • 1,023
  • 1
  • 11
  • 30
  • is this a process that have a start and end or is a server type process that is going to live forever ? – Vidal Jun 25 '20 at 15:47
  • Unless I'm misunderstanding something, you can't have a background process _and_ "output something", it is either one or the other. Your background process itself can write to disk/database/whatever, but the foreground that is responsible for kicking off the background process will continue on and never receive the output (unless you put a looping sleep lock but that would defeat the purpose of a background process). So basically I think you need to write to `/dev/null` as those other posts say. If you need to capture anything, that logic needs to be in `backgroundOutput.php` or a wrapper – Chris Haas Jun 25 '20 at 17:14
  • @ChrisHaas i have tried /dev/null still not run bgprocess.php code in background by exec().l just need to run bgprocess.php in background.if have simple in bgprocess.php then 'Hello' want to print in backgroundOutput.php.Hopes you understand.. – Bhavesh Chauhan Jun 26 '20 at 08:32

0 Answers0