Re: redirecting output for a spawned child process..

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



You can use a PHP workarround. Install a custom ob_handler, that has a
static file descriptor, and writes all output to the file. In order to also
see everything, you need to also activate implicit flush. i know that there
would be lots of elegant ways to do this on linux in C, but AFAIK php
doesn't ofer anything like that.

here's some code (untested)

<?php
function _myObHandler($sBuf)
{
   static $rFile = null;
   if ($rFile === null)
   {
      /// open the file here
   }
   fwrite($rFile,$sBuf);
   return $sBuf;
}

ob_start('_myObHandler');
ob_implicit_flush();

2009/2/21 Per Jessen <per@xxxxxxxxxxxx>

> bruce wrote:
>
> > hi...
> >
> > got a situation where i have a parent app that spawns children. trying
> > to figure out how to get the output of the spawned/forked children to
> > be written to an external file...
>
> Normally I would use freopen() on stdout and stderr, but that's not
> available in PHP :-(
>
> > can't seem to find any examples of how to accomplish this... do i have
> > to insert something within the child php app itself to redirect the
> > output that's currently being sent to the term? i'd prefer to have the
> > output displayed, as well as redirected...
>
> You basically need to do something about the stdin, stdout and stderr
> file descriptors that your child inherited from the parent at time of
> fork().  I can't seem to find many PHP functions that deal with file
> descriptors though.
>
>
>
> --
> Per Jessen, Zürich (2.6°C)
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


-- 
Alpar Torok

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux