note 106905 added to function.stream-get-contents

From: Date: Sun, 18 Dec 2011 03:12:00 +0000
Subject: note 106905 added to function.stream-get-contents
Groups: php.notes 
Request: Send a blank email to php-notes+get-185107@lists.php.net to get a copy of this message
In that case when stream_get_contents/fread/fgets or other stream reading functions block indefinitely your script because they don't reached the limit of bytes to read use the socket_get_meta_data function to figure out the number of the bytes to read. It returns an array that contains a key named 'unread_bytes' and then pass that number to your favourite stream reading functions second parameter to read from the stream. Maybe a good workaround to use the stream_select function, and set the socket to non-blocking mode with the use of stream_set_blocking($stream, 0). In this case the socket reading functions work properly. Cheers, Ervin ---- Server IP: 69.147.83.197 Probable Submitter: 176.241.40.247 ---- Manual Page -- http://www.php.net/manual/en/function.stream-get-contents.php Edit -- https://master.php.net/note/edit/106905 Del: integrated -- https://master.php.net/note/delete/106905/integrated Del: useless -- https://master.php.net/note/delete/106905/useless Del: bad code -- https://master.php.net/note/delete/106905/bad+code Del: spam -- https://master.php.net/note/delete/106905/spam Del: non-english -- https://master.php.net/note/delete/106905/non-english Del: in docs -- https://master.php.net/note/delete/106905/in+docs Del: other reasons-- https://master.php.net/note/delete/106905 Reject -- https://master.php.net/note/reject/106905 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#185107) next »