Re: Bug in stream_socket_server()?
| From: | Nathan Rixham | Date: | Tue, 11 Dec 2007 22:16:37 +0000 |
| Subject: | Re: Bug in stream_socket_server()? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-265723@lists.php.net to get a copy of this message | ||
Would this class as a test?
<?php
$socket = stream_socket_server("tcp://0.0.0.0:8000", $errno, $errstr);
if (!$socket) {
echo "$errstr ($errno)<br />\n";
} else {
while (is_resource($conn = stream_socket_accept($socket, 30))) {
while (is_resource($conn) && $pkt = stream_get_line($conn, 1000000, "\n")) {
fwrite($conn, '>>>>');
sleep(10);
echo $pkt;
}
}
}
?>
I then sent 2*384kb loads per second through a terminal to it without problems, 10 minutes since i stopped writing data to it and it's still echoing out 1 line every 10 secs!
Nathan
René Fournier wrote:
"If you want a high speed socket server, use the low-level sockets instead (socket_create/bind/listen). The stream_socket_server version appears to have internal fixed 8k buffers that will overflow if you don't keep up by reading. This is a serious problem if you an application that reads the socket for messages and then, say, saves the result in a database. The delay while it is busy processing means you can't read the data in time unless you get involved in muti-threading. With the the low-level functions, the OS quietly buffers TCP/IP packets so there is no problem (tested on Windows XP Professional)." ( http://php.oregonstate.edu/manual/en/function.stream-socket-server.php#67837 ) Has anyone confirmed this? I am doing tests with a stripped-down multi-client socket server, wonder if this issue is causing some of the problems I've seen. ...Rene