42 if($this->stream !== null)
return;
44 $host = strval($this->config[
"host"]);
45 $port = strval($this->config[
"port"]);
47 $address =
"tcp://" . $host .
":" . $port;
48 $timeout = intval($this->config[
"timeout"]);
50 $this->stream = @stream_socket_client($address, $errno, $errstr, $timeout);
52 if($this->stream === FALSE)
57 @stream_set_timeout($this->stream, $timeout);
58 @stream_set_blocking($this->stream, $this->config[
"blocking"] ? 1 : 0);
68 if($this->stream === null)
return;
82 public function read($length = 4096)
87 $data = @stream_get_contents($this->stream, $length);
112 while(!$line->endsWith($token))
116 $data = @fgets($this->stream, 4096);
124 $line->append($token);
133 $line->append($data);
137 return $line->trim();
150 @stream_socket_sendto($this->stream, $data);
164 $size = strlen($data);
167 for($seek = 0 ;$seek < $size;)
170 $pack = $rest < $pack ? $rest : $pack;
171 $buff = substr($data, $seek, $pack);
174 if($seek >= $size) $buff .= $separator;