I'm writing a tool that connects to a server, sends request, read response, and send other commands.
The problem is that the response the server send can vary in terms of lines (it's always at least one line, but can be 3, 5 lines), and he can send one line, wait a few seconds, then send others lines.
Is there a way to read all the incoming data until they stop?
Maybe I have to change for sockets
?
Here are my tries :
$fp = fsockopen("www.example.com", 25, $errno, $errstr, 30);
-
while(fgets($fp, 1024)) {} // hangs
-
fgets($fp, 4096); // works, but doesn't get the multiple lines
-
while(!feof($fp)){
fgets($fp, 1024);
}
// hangs
-
while(($c = fgetc($fp))!==false) {
var_dump($c);
}
// hangs