If I access the REST server script manually it outputs all of the (json encoded) data without any problems.
my rest client script uses fsockopen to open the connection and then fgets to read the data in a loop.
It works perfectly with smaller amounts of data.
but after a certain point, It will add a hex value to the beginning of my json encoded data string and not get all of the data.
the data is all text json-encoded as an array of objects. With my current data, if I request 45 objects, It works successfully,
but at >= 46 it doesn't.
the actual size of the data is:
45 objects - 7,969 bytes
46 objects - 8,118 bytes
this data is all on one line, so my script loops through the response, reading the response header line by line with fgets()
and then reads the entire data object in one fgets() call. Is this a bad idea? Am I hitting some maximum size that can be read with one fgets() call?
Here's my code:
Code: Select all
$sock = fsockopen($host, $port);
fputs($sock, "GET $path HTTP/1.1\r\n");
fputs($sock, "Host: $host\r\n");
fputs($sock, "Content-type: application/x-www-form-urlencoded\r\n");
fputs($sock, "Connection: close\r\n\r\n");
// get the result.
$result = "";
while (!feof($sock))
{ //length parameter increased to this crazy number while debugging :-/
$result .= fgets($sock,9999768);
}
fclose($sock);
return $result;