cannot read full data using fsockopen and fgets

Discussion in 'PHP' started by sergkr, May 10, 2007.

  1. #1
    Hi everybody!

    I am not sure if my problem is configuration or programming issue.

    I have a script that reads data from remote server via socket connection, something like this:

    ...
    $fp = fsockopen($conn_host, $conn_port);

    stream_set_blocking($fp,0);
    while (!feof($fp) && !$stop) {
    $line = fgets($fp, 1024);
    echo($line);
    flush();
    } //while
    stream_set_blocking($fp,1);
    fclose($fp);

    I put it on a web site and it worked fine for several days. Then it stopped working properly. Host provider assured me thy did no do any changes in configuration. They also restarted the server but that did not help.

    I did some testing and see that the scripts works in following way:

    1. It opens the socket connection successfully.
    2. It reads some block of data
    3. Then it hangs up for 30 sec and throws error
    "Maximum execution time of 30 seconds exceeded in line XX" where line # is the line with fgets function.

    Any idea why it this problem happen? It is really critical issue.

    Thanks.
     
    sergkr, May 10, 2007 IP
  2. gibex

    gibex Active Member

    Messages:
    1,060
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    95
    #2
    execution time is your problem. try to put a higher value in your your php.ini
     
    gibex, May 10, 2007 IP