This is what I have so far..

<?php
$host = "127.0.0.1";
$port = 1234;

$fp = fsockopen ($host, $port, $errno, $errstr, 30);
if (!$fp) {
echo "$errstr ($errno)<br>\n";
}
else {

fputs ($fp, "USERNAME,PASSWORD\n");
$rs = fgets($fp,1024); echo $rs;


fputs ($fp, "DEVICES\n");
$rs = fgets($fp,1024); echo $rs;

}
?>

I login with username and password and this works fine.
I send Devices and I'm returned one line.

If I do this on a telnet session I get 4 - 8 lines depending on the unit I'm connected to.

How do I get all the data back using php ??
Thanks

    The function [man]fgets/man only retrieves one line at a time. Thus, if you want to get multiple lines, you simply call the function multiple times; see the coding example on the manual page for [man]fgets/man.

      Thanks
      I did try the example, and while mine returns one line... the example returns nothing and finally timesout.

      Any other ideas ?

      Thanks for your help.

        Can you show us what the code above looks like after you modified it? It should be as simple as wrapping the call to fgets() in a loop that continues to call the function until no more "lines" can be fetched from the stream.

          Thanks for the reply.
          This is my test code !

          <?php
          $handle = @fsockopen ("127.0.0.1", 1234, $errno, $errstr, 30);
          fputs ($handle, "USERNAME,PASSWORD\n");
          
          
          if ($handle) {
              while (($buffer = fgets($handle, 4096)) !== false) {
                  echo $buffer;
              }
              if (!feof($handle)) {
                  echo "Error: unexpected fgets() fail\n";
              }
              fclose($handle);
          }
          ?>

          Any ideas ?

            Maybe you need to do a [man]rewind/man before starting the loop?

              Thanks for the advice.

              rewind results in this error :

              Warning: rewind(): supplied argument is not a valid stream resource in

              Any ideas ?

                [man]fgets[/man] stops reading at the first line break (if the buffer isn't filled first); [man]fread[/man] doesn't.

                There's a warning note on the [man]feof[/man] page warning about it hanging if the server doesn't close the socket.

                  Write a Reply...