jmurch Posted March 7, 2013 Share Posted March 7, 2013 (edited) I am reading a stream using '$input = trim(fread($socket, 16384));' and everything is working fine until the length of data from the stream exceeds 4078. At 4078 I stop for some reason reading the stream. I am wondering why this works (up to 4078): '$input = trim(fread($socket, 16384));' But this does not: '$input = stream_get_contents($socket);' Other parameters for the stream are: stream_set_blocking($con, true); stream_socket_enable_crypto($con, true, STREAM_CRYPTO_METHOD_TLS_SERVER); handle_incoming_connection($con, $client); $res = stream_context_create($streamopts); if ($res === false) { System_Daemon::err('error when creating stream'); System_Daemon::stop(); exit(1); } $master = stream_socket_server( "tcp://$host:$port", $errno, $errstr, STREAM_SERVER_BIND | STREAM_SERVER_LISTEN, $res ); if ($master === false) { System_Daemon::err('stream_socket_server(): [%s] %s', $errno, $errstr ); System_Daemon::stop(); exit(1); } stream_socket_enable_crypto($master, false); function handle_incoming_connection($socket, $client) { $input = trim(fread($socket, 16384)); if (($input == null) || ($input == 'exit') ) { return; } Any help would be greatly appreciated. TIA, Jeff Edited March 7, 2013 by jmurch Quote Link to comment https://forums.phpfreaks.com/topic/275370-reading-socket-stream/ Share on other sites More sharing options...
DavidAM Posted March 7, 2013 Share Posted March 7, 2013 ... At 4078 I stop for some reason reading the stream. ...What exactly does this mean? Does the script abort with no output, or does the script hang up? With a BLOCKING stream, fread is going to wait ("block") until it gets (in this case) 16,384 bytes of data. So the script may seem to hang up. If the script is aborting, you may be exhausting the memory limits of PHP. Make sure you have error reporting turned on so you can see the memory error. Note: please use [ code] [ /code] tags around your code when posting on the forum. It makes it much easier to read. Quote Link to comment https://forums.phpfreaks.com/topic/275370-reading-socket-stream/#findComment-1417241 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.