note 118556 added to function.stream-get-contents
| From: | divinity76+nospam at gmail dot com | Date: | Sun, 27 Dec 2015 23:24:04 +0000 |
| Subject: | note 118556 added to function.stream-get-contents | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-204548@lists.php.net to get a copy of this message | ||
/*
* problem: stream_get_contents blocks / is very slow.
* I have tried
* 1: stream_set_blocking, doesn't make a difference.
* 2: stream_get_meta_data['unread_bytes'] = ITS BUGGED, ALWAYS SAYS 0.
* 3: feof(): ALSO EFFING BLOCKING
* 4: my_stream_get_contents hack... kinda working! :D
*/
function my_stream_get_contents ($handle, $timeout_seconds = 0.5)
{
$ret = "";
// feof ALSO BLOCKS:
// while(!feof($handle)){$ret.=stream_get_contents($handle,1);}
while (true) {
$starttime = microtime(true);
$new = stream_get_contents($handle, 1);
$endtime = microtime(true);
if (is_string($new) && strlen($new) >= 1) {
$ret .= $new;
}
$time_used = $endtime - $starttime;
// var_dump('time_used:',$time_used);
if (($time_used >= $timeout_seconds) || ! is_string($new) ||
(is_string($new) && strlen($new) < 1)) {
break;
}
}
return $ret;
}
----
Server IP: 72.52.91.14
Probable Submitter: 85.164.164.163
----
Manual Page -- http://php.net/manual/en/function.stream-get-contents.php
Edit -- https://master.php.net/note/edit/118556
Del: integrated -- https://master.php.net/note/delete/118556/integrated
Del: useless -- https://master.php.net/note/delete/118556/useless
Del: bad code -- https://master.php.net/note/delete/118556/bad+code
Del: spam -- https://master.php.net/note/delete/118556/spam
Del: non-english -- https://master.php.net/note/delete/118556/non-english
Del: in docs -- https://master.php.net/note/delete/118556/in+docs
Del: other reasons-- https://master.php.net/note/delete/118556
Reject -- https://master.php.net/note/reject/118556
Search -- https://master.php.net/manage/user-notes.php