php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #1854 fsockopen does not work when used multiple times
Submitted: 1999-07-23 18:27 UTC Modified: 1999-07-23 18:55 UTC
From: taoliang at cdr dot stanford dot edu Assigned:
Status: Closed Package: Other
PHP Version: 3.0.8 OS: Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: taoliang at cdr dot stanford dot edu
New email:
PHP Version: OS:

 

 [1999-07-23 18:27 UTC] taoliang at cdr dot stanford dot edu
The following function will work only once when called multiple times.  My guess is that the file pointer have to be reset (feof($fp) shows true after the first time the function is called).

function get_data() {
        $fp = fsockopen("www.php.net", 80, &$errno, &$errstr);

        if (!$fp) {
                echo "$errstr ($errno)<br>\n";
                $err = 1;
        } else {
                fputs($fp,"GET /quote.asp?Symbol=$ticker HTTP/1.0\n\n");
                echo "$fp, ", feof($fp), "\n";
                while(!feof($fp)) {
                        $resp .= fgetss($fp,4096);
                }
                fclose($fp);
        }
        echo $resp;
}


Let's say I do the following:

for ($i=0;$i<10;$i++) {
        echo "start...\n";
        get_data();
}

It will return valid output for the first time, and the rest will just be blank.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [1999-07-23 18:55 UTC] sas at cvs dot php dot net
That should be fixed completely in CVS. You might try the CVS version. More information:

http://cvs.php.net
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Thu Oct 08 15:00:02 2026 UTC