note 100596 added to function.socket-read

From: Date: Mon, 25 Oct 2010 22:13:52 +0000
Subject: note 100596 added to function.socket-read
Groups: php.notes 
Request: Send a blank email to php-notes+get-173456@lists.php.net to get a copy of this message
A couple of things: The maximum amount that can be read by socket_read is, I think, 133693415 bytes, from my experimentation. Also, here is a quick function if anyone wants to read indefinitely until a certain character is sent: <?php function socket_read_normal($socket, $end=array("\r", "\n")){ if(is_array($end)){ foreach($end as $k=>$v){ $end[$k]=$v{0}; } $string=''; while(TRUE){ $char=socket_read($socket,1); $string.=$char; foreach($end as $k=>$v){ if($char==$v){ return $string; } } } }else{ $endr=str_split($end); $try=count($endr); $string=''; while(TRUE){ $ver=0; foreach($endr as $k=>$v){ $char=socket_read($socket,1); $string.=$char; if($char==$v){ $ver++; }else{ break; } if($ver==$try){ return $string; } } } } } ?> You can have either an array of single characters (multi-char values are automatically cut down) or one string. Multiple strings are difficult to do, because you would need to decide which string the current character should 'belong' to (if that makes any sense?) and allow for multiple strings being looked at simultaneously. To put it bluntly, I can't be bothered :) ---- Server IP: 87.124.126.138 Probable Submitter: 82.68.127.14 (proxied: 82.68.127.14) ---- Manual Page -- http://www.php.net/manual/en/function.socket-read.php Edit -- https://master.php.net/note/edit/100596 Del: integrated -- https://master.php.net/note/delete/100596/integrated Del: useless -- https://master.php.net/note/delete/100596/useless Del: bad code -- https://master.php.net/note/delete/100596/bad+code Del: spam -- https://master.php.net/note/delete/100596/spam Del: non-english -- https://master.php.net/note/delete/100596/non-english Del: in docs -- https://master.php.net/note/delete/100596/in+docs Del: other reasons-- https://master.php.net/note/delete/100596 Reject -- https://master.php.net/note/reject/100596 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#173456) next »