socket_read() returns only headers, not the actual response

Viewed 538

I'm running

$data = socket_read($socket, 2048, PHP_BINARY_READ);

that should return a string like this

// $data == ' 1840 kg G 008765 A '

but instead it returns

Original response: HTTP/1.1 200 OK
Date: Wed, 19 Feb 2003 09:00:00 GMT
Server: MoxaHttp/1.0
Pragma: no-cache
Cache-Control: no-cache
Content-type: text/html
Content-length: 450

which is looks like headers of the data returned.

socket_send is configured correctly, we have other clients with same settings and they return correct values.

Can you please say what's the problem, and why i'm not getting expected string?

UPDATE:

I repeated socket_read() multiple times to read full string it it is:

Original response: HTTP/1.1 200 OK
Date: Wed, 19 Feb 2003 09:00:00 GMT
Server: MoxaHttp/1.0
Pragma: no-cache
Cache-Control: no-cache
Content-type: text/html
Content-length: 450
Set-Cookie: ChallID=1656
<HTML><HEAD><TITLE>NPort Web Console</TITLE></HEAD> <FRAMESET rows=57,1* frameborder=NO> <FRAME name=top scrolling=NO target=contents src=top.htm noresize> <FRAMESET cols=200,*> <FRAME name=contents target=main src=contents.htm> <FRAME name=main src=main.htm marginwidth=0 marginheight=0 scrolling=auto> </FRAMESET> <NOFRAMES><BODY background=bg.gif><P>This page uses frame, but your browser doesn't support.</P></BODY> </NOFRAMES> </FRAMESET></HTML>

so it's look like it returns some different things, that are suppose to be read by other program.

1 Answers

Did you tried?:

echo "Reading response:\n\n";
$buf = 'This is my buffer.';
if (false !== ($bytes = socket_recv($socket, $buf, 2048, MSG_WAITALL))) {
    echo "Read $bytes bytes from socket_recv(). Closing socket...";
} else {
    echo "socket_recv() failed; reason: " . socket_strerror(socket_last_error($socket)) . "\n";
}
socket_close($socket);
Related