slow reading from socket

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Wim Smit

    slow reading from socket

    I am writing a script that connects to somekind of telnet server, and
    returns the answers the server gives.

    Everything works fine until I have to start writing a loop. I want to give a
    command which will give an answer of more than 1 line, but I do not know how
    many lines it will be in total.



    So I wrote something like this:

    // get the list

    fputs ($fp, "list all\n");

    $list = "1";

    while (!$list=="") {

    $list = fgets($fp, 50);

    echo "$list<BR>" ;

    }



    I tried also a few other loops like "while ($i < 100) or while(!feof) etc.
    but they take over 40 seconds to show 4 lines of text.



    But if I would do something like:

    fputs ($fp, "list all\n");

    $line1 = fgets($fp, 50);

    $line2 = fgets($fp, 50);

    $line3 = fgets($fp, 50);

    etc.



    It is ready within a second. Anybody knows how I can speed this up? I
    already tried other functions like fread, fpassthru, all worked, but as
    evenly slow.



    Who can help me out?



    Thanks!

    And apologies if this is a n00b question.


Working...