losing STDIN

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Karstens Rage

    losing STDIN

    I am using:

    PHP 5.0.4 (cli) (built: Feb 24 2006 16:34:55)
    Copyright (c) 1997-2004 The PHP Group
    Zend Engine v2.0.4-dev, Copyright (c) 1998-2004 Zend Technologies

    I wrote a script which basically sits in a while loop doing:

    while (!feof(STDIN)) {
    $line = fgets(STDIN);
    // do something with $line
    }

    I pipe a tail command into this script like:

    tail -n0 -F /var/log/mystuff.log | php -c /etc/php.ini myscript.php &

    Everything works fine until logrotate rotates mystuff.log. Then the
    script just hangs there and no longer processes anything. It doesn't
    seem to drop out of the while loop but I have to put some more debugging
    statements in to see if I can figure out what is going on. Any ideas. I
    don't really get how to deal with feof when the file is rotated.

    k
  • Alvaro G. Vicario

    #2
    Re: losing STDIN

    *** Karstens Rage escribió/wrote (Wed, 13 Sep 2006 09:37:56 -0700):
    tail -n0 -F /var/log/mystuff.log | php -c /etc/php.ini myscript.php &
    >
    Everything works fine until logrotate rotates mystuff.log. Then the
    script just hangs there and no longer processes anything.
    I believe you can configure logrotate to shut down you script and launch it
    again. That's what allows, for instance, to get Apache logs rotated. Could
    that be a solution?


    --
    -+ http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
    ++ Mi sitio sobre programación web: http://bits.demogracia.com
    +- Mi web de humor con rayos UVA: http://www.demogracia.com
    --

    Comment

    Working...