From:             [EMAIL PROTECTED]
Operating system: RedHat 7.3
PHP version:      4CVS-2003-01-21 (stable)
PHP Bug Type:     Sockets related
Bug description:  fgets() does not time-out if connection is lost

I've been writing a CLI-based script that connects to an xml wirefeed and
continually reads the data with fgets() and parses it accordingly.  The
script works fine, but occasionally the feed server goes down for
maintenance, etc.  That in itself isnt a problem, but when the connection
to the feed is lost, fgets() stalls and never times out regardless of the
stream_set_timeout() usage.  I have written the following scripts to
verify the problem (note that the "server" script is only to help test the
fgets() bug in the "client" script).

I run this script (the "server" script) on my workstation (running XP w/
PHP 4.3.0 in CLI mode) to listen on a socket:

<?php

        error_reporting(E_ALL);
        set_time_limit(0);
        ob_implicit_flush();

        $sock = socket_create (AF_INET, SOCK_STREAM, 0);
        socket_bind($sock, "192.168.1.11", "10000");
        socket_listen($sock, 5);
        $msgsock = socket_accept($sock);
        do {
                $buf = socket_read($msgsock, 2048);
        } while (true);
        socket_close($msgsock);
        socket_close($sock);

?>

Then I run this script (the "client" script) on my linux box (running
RH7.3 w/ PHP 4CVS-2003-01-20 (stable) in CLI mode) to connect to the
socket:

<?php

        error_reporting(E_ALL);
        set_time_limit(30);
        ob_implicit_flush();

        $fp = fsockopen("192.168.1.10", 10000, $errno, $errstr, 10);
        if ($fp) {
                stream_set_timeout($fp, 10);
                $data = fgets($fp);
                $sinfo = socket_get_status($fp);
                echo ($sinfo["timed_out"]?"socket timed out\n":"eof\n");
                fclose($fp);
        } else
                echo "unable to connect\n";

?>

The client script will time-out properly when I leave the server script
running.  But if I run the client script, then CTRL-C my server script,
the client script never times out.  It sits at the fgets() forever, even
though I've set_time_limit(30) as well as stream_set_timeout(10).

Since the script just sits there and never "crashes" to generate a
corefile, I haven't been able to perform a backtrace.  Even though i've
compiled PHP with --enable-debug, killing the script with CTRL-C doesn't
generate a corefile (should it?).  If a bt would help, please let me know
how I can generate a corefile with the CLI version of PHP.

I've configured PHP as as follows:

'./configure' '--with-apxs' '--with-config-file-path=/etc'
'--with-mysql=/usr' '--with-gzip' '--with-xml' '--with-gd' '--with-zlib'
'--with-freetype' '--with-ttf' '--enable-debug' 

Note that I have also verified this problem on a second linux box running
RH8 w/ PHP4.3.0.  

Any help would be appreciated!

-- 
Edit bug report at http://bugs.php.net/?id=21809&edit=1
-- 
Try a CVS snapshot:         http://bugs.php.net/fix.php?id=21809&r=trysnapshot
Fixed in CVS:               http://bugs.php.net/fix.php?id=21809&r=fixedcvs
Fixed in release:           http://bugs.php.net/fix.php?id=21809&r=alreadyfixed
Need backtrace:             http://bugs.php.net/fix.php?id=21809&r=needtrace
Try newer version:          http://bugs.php.net/fix.php?id=21809&r=oldversion
Not developer issue:        http://bugs.php.net/fix.php?id=21809&r=support
Expected behavior:          http://bugs.php.net/fix.php?id=21809&r=notwrong
Not enough info:            http://bugs.php.net/fix.php?id=21809&r=notenoughinfo
Submitted twice:            http://bugs.php.net/fix.php?id=21809&r=submittedtwice
register_globals:           http://bugs.php.net/fix.php?id=21809&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=21809&r=php3
Daylight Savings:           http://bugs.php.net/fix.php?id=21809&r=dst
IIS Stability:              http://bugs.php.net/fix.php?id=21809&r=isapi
Install GNU Sed:            http://bugs.php.net/fix.php?id=21809&r=gnused

Reply via email to