From:             [EMAIL PROTECTED]
Operating system: Linux
PHP version:      4.2.0
PHP Bug Type:     Sockets related
Bug description:  reading data from fsockopen/fopen times out

I'm having trouble reading the data from responses over socket
connections.

For instance, this code (similar to that on the online docs for fsockopen,
example 1),

$fp = fsockopen ("localhost", 80, $errno, $errstr, 10);
if (!$fp) {
    echo "$errstr ($errno)<br>\n";
} else {
    fputs ($fp, "GET / HTTP/1.0\r\nHost: localhost\r\n\r\n");
    while (!feof($fp)) {
        echo fread ($fp,128);
    }
    fclose ($fp);
}

results in a timeout on the fread line (even if I let it run for 300
seconds). I also tried the udp example (example 2,
"fsocketopen("udp://127.0.0.1"...) on the documentation page and had the
same problem. Also note that the fourth parameter to the fsockopen doesn't
seem to be working in this case since this code took 300 seconds to
timeout, not the 10 specified. The CPU usage by php went to 100% during
the attempted excution of this code.

I have the same problem if I try using fopen to open a web page and read
the data (as in the below code). It always hangs on the fread or fgets of
the file pointer with the response in it. I know the remote service (e.g.,
the web server) is actually sending a response string because I can see it
in the server log.

My hardware is a bit unusual. I'm running SuSe linux kernel 2.4.7-SuSe-SMP
under VM on an IBM mainframe. I had these errors with php versions 4.2.0,
4.1.2, and 4.0.6. 

I tried to replicate the problem on an intel box with RedHat 7.2 kernel
2.4.9 and php 4.0.6, but failed. The most abnormal behaviour I could find
on that platform was that "fopen" and then "fread" of remote or local web
pages took *way* too long.

For instance, this code eventually got the desired response, but it took
about 20-24 seconds:

$fp = fopen("http://localhost/";, "r");
$text = fread($fp, 20);
fclose($fp);
echo $text;

If I used fsockopen (e.g., with the first piece of code above) on this box
it ran in less than a second and gave the expected response. 

Any help is much appreciated. I really need to figure out how to read data
over sockets on that first machine.

Thanks,
Graham Warden
[EMAIL PROTECTED]

p.s.
This is somewhat related to my previous bug post (#10996) about a year
ago.
-- 
Edit bug report at http://bugs.php.net/?id=16892&edit=1
-- 
Fixed in CVS:        http://bugs.php.net/fix.php?id=16892&r=fixedcvs
Fixed in release:    http://bugs.php.net/fix.php?id=16892&r=alreadyfixed
Need backtrace:      http://bugs.php.net/fix.php?id=16892&r=needtrace
Try newer version:   http://bugs.php.net/fix.php?id=16892&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=16892&r=support
Expected behavior:   http://bugs.php.net/fix.php?id=16892&r=notwrong
Not enough info:     http://bugs.php.net/fix.php?id=16892&r=notenoughinfo
Submitted twice:     http://bugs.php.net/fix.php?id=16892&r=submittedtwice

Reply via email to