socket_write buffer problem
| From: | Richard Luckhurst | Date: | Mon, 22 Jan 2007 00:52:29 +0000 |
| Subject: | socket_write buffer problem | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-247527@lists.php.net to get a copy of this message | ||
Hi List
I am working with an application that has to run as a socket listener. It
receives a string from another application on a certain socket and then does
some processing and then passes the result back to the client application via
the socket. Here is the listener code I am using
while(true)
{
$client = socket_accept($socket);
$arev_data = socket_read($client, 1024);
$yresponse = build_XML_request($arev_data);
socket_write($client, $yresponse);
socket_close($client);
}
socket_close($socket);
The application is working fine but I have just noticed that when the $yresponse
variable is larger than 1024 bytes the string returned to the client is
truncated. I just had a look at the php manual for socket_write and it
mentions that truncating the data at the buffer size can be a problem. The
manual does not offer any possible solutions though. I am stumped here as the
value for $yresponse will often be larger than 1024 bytes and its length is
quite variable.
Does anyone have any suggestions on how I can make sure the entire contents of
$yresponse are passed back to the client?
Regards,
Richard Luckhurst
Product Development
Exodus Systems - Sydney, Australia.