php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #1432 fgets() fails on certain sockets
Submitted: 1999-05-21 04:28 UTC Modified: 2001-10-02 04:23 UTC
From: adam at musicseek dot net Assigned:
Status: Closed Package: Feature/Change Request
PHP Version: 4.0 OS: Win32
Private report: No CVE-ID: None
 [1999-05-21 04:28 UTC] adam at musicseek dot net
I use PHP/3.06 win32 for writing a web crawler which
indexes URL's.

The indexer has no problems, except on ONE url that I
know of so far which seems to be, as far as I
can ascertain related to the fgets()
function failing to work.

fgets() will not read data from any socket connected
via fsockopen to www.hutman.com port 80. I know this might
seem very strange, but fgets() never seems to be able to determine EOF and hence sits there forever doing nothing.
I have used a raw telnet session to try and debug this and cannot find why PHP would do this -- it works fine on every
other URL in the database.

Here is some code that may help:

    $sock = fsockopen("www.hutman.com",80);

    if ($sock)
    {
      fputs($sock,"HEAD /dreg/facade/songs/aftk.mp3 HTTP/1.1\n");
      fputs($sock,"Host: www.hutman.com\n");
      fputs($sock,"User-Agent: HTTP-crawler/1.0\n");
      fputs($sock,"Connection: close\n\n");

/* at this point the server responds .. and it indeed does in a telnet session, but PHP simply wont read the data returned AT ALL. */

      while ($buf = fgets($sock,128))
      {
        $response = $response . $buf;
        echo $buf;
      }

No variations of this will work.. the fgets() function will timeout after a while.

i have tried while (!feof($sock)) as well, which exhibits similar behaviour, but seems to NEVER return from the fgets() call .. never times out.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [1999-05-28 07:52 UTC] sas at cvs dot php dot net
fgets recognizes a carriage return (CR, '\n', 0xod)  as a end-of-line only. The site in question uses line feeds (LF, ?\r?, 0x0a) as line delimiters.

Moving the report over to feature requests.
 [2001-02-10 13:17 UTC] jimw@php.net
refiling as a bug against 4.0.
 [2001-07-22 12:29 UTC] andy@php.net
reclassified
 [2001-07-23 18:46 UTC] andy@php.net
does this happen in the latest version?
 [2001-10-02 04:23 UTC] sander@php.net
No feedback. Closing.
 [2004-06-12 04:30 UTC] mugu at mugu dot com
Guy men keep off
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 18:01:29 2024 UTC