예제 #1
0
    public function query($text)
    {
        $head = <<<_HEADER_
<?xml version="1.0" ?>
<wordsegmentation version="0.1">
<option showcategory="1" />
<authentication username="******" password="******" />
<text>
_HEADER_;
        $footer = <<<_FOOT_
</text>
</wordsegmentation>
_FOOT_;
        $this->data_send = $text;
        $text = str_replace("&", " ", $text);
        $querystr = $head . $text . $footer;
        $tempxml = simplexml_load_string($querystr);
        $resp = array();
        if ($tempxml) {
            if (stream_socket_sendto($this->sock, $tempxml->asXML())) {
                do {
                    $ttt = stream_socket_recvfrom($this->sock, 65525);
                    $ttt = iconv('big5', 'utf-8', $ttt);
                    $resp[] = $ttt;
                } while (!simplexml_load_string(implode($resp)));
                return $this->data_recv = html_entity_decode(implode($resp));
            }
        } else {
            $this->data_recv = 0;
            return null;
        }
    }
예제 #2
0
 public function processMessage($message, $client)
 {
     $event = $message->event;
     $data = $message->data;
     $uuid = $message->uuid;
     if ($event == "beforeEach") {
         $data = $this->runner->runBeforeEachHooksForTransaction($data);
         $data = $this->runner->runBeforeHooksForTransaction($data);
     }
     if ($event == "beforeEachValidation") {
         $data = $this->runner->runBeforeEachValidationHooksForTransaction($data);
         $data = $this->runner->runBeforeValidationHooksForTransaction($data);
     }
     if ($event == "afterEach") {
         $data = $this->runner->runAfterHooksForTransaction($data);
         $data = $this->runner->runAfterEachHooksForTransaction($data);
     }
     if ($event == "beforeAll") {
         $data = $this->runner->runBeforeAllHooksForTransaction($data);
     }
     if ($event == "afterAll") {
         $data = $this->runner->runAfterAllHooksForTransaction($data);
     }
     $messageToSend = ['uuid' => $uuid, 'data' => $data, 'event' => $event];
     $messageToSend = json_encode($messageToSend);
     stream_socket_sendto($client, $messageToSend . self::MESSAGE_END);
 }
예제 #3
0
 /**
  * 发送UDP数据包
  * @param $data
  * @param $port
  */
 static function _send_udp($data, $port)
 {
     if (self::$enable) {
         $cli = stream_socket_client('udp://' . self::$sc_svr_ip . ':' . $port, $errno, $errstr);
         stream_socket_sendto($cli, $data);
     }
 }
예제 #4
0
 public function close_moniter()
 {
     $dmainid = trim($_POST['dmainid']);
     //$dmain = trim($_POST['dmain']);
     $dmain_list_db = new Dmain_list();
     $val = $dmain_list_db->close_moniter($dmainid);
     $list = [];
     if (is_array($val) && count($val) > 0) {
         foreach ($val as $value) {
             $list[] = $value->dmain;
         }
     }
     if (count($list) > 0) {
         $list = implode('|', $list);
     } else {
         $list = '';
     }
     //写入redis共享给udp服务器
     $redis = $this->getRedis();
     $dmain_list = $redis->set('dmain', $list);
     $socket = stream_socket_client('udp://211.151.98.92:9501');
     $data = ['control' => 'reload'];
     $data = json_encode($data) . '\\r\\n';
     if (!$socket) {
         exit(json_encode(false));
     } else {
         stream_socket_sendto($socket, $data);
         exit(json_encode(true));
     }
 }
예제 #5
0
 /**
  * {@inheritdoc}
  */
 public function write($string)
 {
     if (!$this->isWritable()) {
         throw new RuntimeException("Stream is not writable");
     }
     return stream_socket_sendto($this->getContext(), $string);
 }
예제 #6
0
 /**
  * {@inheritdoc}
  */
 public function write($data = null)
 {
     if (isset($this->stream) === false) {
         $this->createStream();
     }
     @stream_socket_sendto($this->stream, $data);
     return true;
 }
예제 #7
0
 /**
  * 发送数据给统计系统
  * @param string $address
  * @param string $buffer
  * @return boolean
  */
 public static function sendData($address, $buffer)
 {
     $socket = stream_socket_client($address);
     if (!$socket) {
         return false;
     }
     return stream_socket_sendto($socket, $buffer) == strlen($buffer);
 }
예제 #8
0
파일: UDP.php 프로젝트: greggcz/librenms
 /**
  * Send the data
  *
  * @param $data
  *
  * @return mixed
  */
 public function write($data = null)
 {
     $host = sprintf('udp://%s:%d', $this->config['host'], $this->config['port']);
     // stream the data using UDP and suppress any errors
     $stream = @stream_socket_client($host);
     @stream_socket_sendto($stream, $data);
     @fclose($stream);
     return true;
 }
예제 #9
0
 /**
  * 发送数据给统计系统
  * @param string $address        	
  * @param string $buffer        	
  * @return boolean
  */
 public static function sendData($address, $buffer, $timeout = 10)
 {
     $socket = stream_socket_client('tcp://' . $address, $errno, $errmsg, $timeout);
     if (!$socket) {
         return false;
     }
     stream_set_timeout($socket, $timeout);
     return stream_socket_sendto($socket, $buffer) == strlen($buffer);
 }
예제 #10
0
파일: hb.php 프로젝트: xiaoyjy/retry
 function request($request)
 {
     try {
         $dt = call_user_func($this->callback, NULL, $request);
         if (!empty($dt['data'])) {
             stream_socket_sendto($this->srv, $dt['data'], 0, $this->cli);
         }
     } catch (Exception $e) {
         cy_log(CYE_ERROR, "exception while processing.");
     }
 }
예제 #11
0
 public function run()
 {
     $result = $this->_server->parse($this->_data);
     if (empty($result['a'])) {
         $data = $this->_data;
     } else {
         $this->_server = $this->route($this->_server);
         $data = $this->_server->getData();
     }
     \stream_socket_sendto($this->_conn, $data . "\n");
 }
예제 #12
0
 /**
  * Sends data on the connection.
  *
  * @param string $send_buffer
  * @param bool   $raw
  * @return void|boolean
  */
 public function send($send_buffer, $raw = false)
 {
     if (false === $raw && $this->protocol) {
         $parser = $this->protocol;
         $send_buffer = $parser::encode($send_buffer, $this);
         if ($send_buffer === '') {
             return null;
         }
     }
     return strlen($send_buffer) === stream_socket_sendto($this->_socket, $send_buffer, 0, $this->_remoteAddress);
 }
예제 #13
0
 protected function pingUdp($target, $data)
 {
     if (!$this->monSocket) {
         $this->monSocket = stream_socket_client($target, $errno, $errstr);
     }
     if ($this->monSocket) {
         $post = http_build_query($data, '', '&');
         stream_socket_sendto($this->monSocket, $post);
     } else {
         common_log(LOG_ERR, __METHOD__ . " UDP logging fail: {$errstr}");
     }
 }
예제 #14
0
    public function add($response)
    {
        $contentLength = strlen($response);
        $httpResponse = 'HTTP/1.0 200 OK
Date: ' . (new \DateTime())->format(\DateTIme::RFC822) . '
Server: PHP Robot Framework Remote Server
Connection: close
Content-Type: text/xml
Content-Length: ' . $contentLength . "\r\n" . "\r\n" . $response;
        stream_socket_sendto($this->requestSocket, $httpResponse);
        stream_socket_shutdown($this->requestSocket, STREAM_SHUT_RDWR);
    }
 public function writeSync($data)
 {
     if ($this->writeEvent) {
         $this->loop->removeWriteStream($this->connection);
         $this->writeEvent = false;
     }
     $this->dataBuffer .= $this->buffer->encodeMessage(serialize($data));
     while (strlen($this->dataBuffer) > 0) {
         $this->ThrowOnConnectionInvalid();
         $dataWritten = stream_socket_sendto($this->connection, $this->dataBuffer);
         $this->dataBuffer = substr($this->dataBuffer, $dataWritten);
     }
 }
예제 #16
0
 /**
  * send data to client
  */
 public function write($data)
 {
     $data = strval($data);
     $length = strlen($data);
     if ($length == 0) {
         return 0;
     }
     /* in case of send failed */
     $alreay_sent = 0;
     while ($alreay_sent < $length) {
         $alreay_sent += stream_socket_sendto($this->_socket, substr($data, $alreay_sent));
     }
     return $length;
 }
예제 #17
0
 protected function waitChild()
 {
     if (!$this->pid) {
         $file = sys_get_temp_dir() . '/parallel' . posix_getppid() . '.sock';
         $address = 'unix://' . $file;
         $result = $this->run();
         if ($client = stream_socket_client($address)) {
             stream_socket_sendto($client, serialize([posix_getpid(), $result]));
             fclose($client);
         }
         posix_kill(posix_getpid(), SIGHUP);
         return;
     }
 }
예제 #18
0
 function handleSend()
 {
     $pkt = array_shift($this->packets);
     if ($pkt['peer'] !== null) {
         stream_socket_sendto($this->sock, $pkt['data'], 0, $pkt['peer']);
     } else {
         stream_socket_sendto($this->sock, $pkt['data']);
     }
     $this->packet = null;
     $this->emit('sent', array($pkt));
     if (count($this->packets) == 0) {
         $this->listening = false;
         $this->loop->removeWriteStream($this->sock);
         $this->emit('sent-all');
     }
 }
예제 #19
0
 protected function pollData($address, $port, $command)
 {
     $this->_logger->log(__METHOD__, array('address' => $address, 'port' => $port, 'command' => $command));
     $timeout = 6;
     // !!! PROTOCOL (TCP by default) SHOULD BE IN LOWER CASE !!!
     $uri = 'tcp' . '://' . $address . ':' . $port;
     $this->_logger->log(__METHOD__ . ': Trying to connect', array('uri' => $uri, 'timeout' => $timeout));
     // creates socket connection with IP:port
     $client = @stream_socket_client($uri, $errno, $errstr, $timeout, STREAM_CLIENT_CONNECT);
     if ($client === false) {
         $this->_logger->log(__METHOD__ . ': Client connect error', array('error' => $errstr, 'number' => $errno));
         return false;
     }
     @stream_set_timeout($client, $timeout);
     $this->_logger->log(__METHOD__ . ': Sending command', array('command' => $command));
     $status = @stream_socket_sendto($client, $command . "\n");
     if ($status === false) {
         $erroInfo = $this->getSocketErrorInfo($client);
         $this->_logger->log(__METHOD__ . ': Error on sending command', array('error' => $erroInfo['error'], 'number' => $erroInfo['number']));
         @stream_socket_shutdown($client, STREAM_SHUT_RDWR);
         return false;
     }
     $this->_logger->log(__METHOD__ . ': Sent result', array('Bytes sent' => $status));
     //$time = 0;
     $line = null;
     $message = '';
     $attempt = 1;
     $this->_logger->log(__METHOD__ . ': Starting to read response.');
     // Wait for message end
     while (strpos($line, '$') === false) {
         $line = @fread($client, 1024);
         $this->_logger->log(__METHOD__, array('read line' => $line));
         if (strlen($line) === 0) {
             $this->_logger->log(__METHOD__ . ': Reading timeout exceeded.', array('attempt' => $attempt));
             if ($attempt > 2) {
                 $this->_logger->log(__METHOD__ . ': Exceeded maximun attempt number.');
                 @stream_socket_shutdown($client, STREAM_SHUT_RDWR);
                 return false;
             }
         }
         $message .= $line;
         $attempt++;
     }
     @stream_socket_shutdown($client, STREAM_SHUT_RDWR);
     $this->_logger->log(__METHOD__, array('return' => $message));
     return $message;
 }
예제 #20
0
파일: Buffer.php 프로젝트: domraider/rxnet
 public function write()
 {
     $this->notifyNext(new StreamEvent("/datagram/sending", $this));
     if ($this->remoteAddress === null) {
         // do not use fwrite() as it obeys the stream buffer size and
         // packets are not to be split at 8kb
         $ret = @stream_socket_sendto($this->socket, $this->data);
     } else {
         $ret = @stream_socket_sendto($this->socket, $this->data, 0, $this->remoteAddress);
     }
     if ($ret < 0 || $ret === false) {
         $error = error_get_last();
         $this->notifyError(new \Exception('Unable to send packet: ' . trim($error['message'])));
         return;
     }
     $this->notifyCompleted();
     $this->loop->removeWriteStream($this->socket);
 }
예제 #21
0
파일: Monitor.php 프로젝트: skeetr/skeetr
 protected function sendCommand($command, $multiline, $servers = null)
 {
     if (!$servers) {
         $servers =& $this->servers;
     }
     $output = array();
     foreach ($servers as $server) {
         $stream = $this->getConnection($server);
         $result = stream_socket_sendto($stream, $command . "\n");
         if (!$multiline) {
             $data = $this->readCommandSingleLine($stream);
         } else {
             $data = $this->readCommandMultiLine($stream);
         }
         $output[$server] = $data;
     }
     return $output;
 }
예제 #22
0
function _resolv_query_udp($host, $timeout, $ns, $query = ResourceQTypes::ALL)
{
    $requestPacket = _resolv_build_request_packet($host, $query);
    // Send request
    $socket = stream_socket_client("udp://{$ns}:53");
    stream_socket_sendto($socket, $requestPacket);
    $r = [$socket];
    $w = $e = [];
    list($sec, $usec) = _resolv_calculate_timeout($timeout);
    if (!stream_select($r, $w, $e, $sec, $usec)) {
        throw new Exception("Request timeout");
    }
    // Decode response message
    $decoder = (new DecoderFactory())->create();
    $responsePacket = fread($socket, 512);
    $response = $decoder->decode($responsePacket);
    fclose($socket);
    return [!$response->isTruncated(), $response];
}
예제 #23
0
 /**
  * 发送数据到监控进程
  * @param int $cmd
  * @param mix $data
  * @param string $address
  */
 protected static function sendData($cmd, $data, $address = 'udp://0.0.0.0:10203')
 {
     if (class_exists('JMProtocol')) {
         $packge = new JMProtocol();
         $packge->header['sub_cmd'] = $cmd;
         $packge->body = json_encode($data);
         $socket = stream_socket_client($address);
         $buffer = $packge->getBuffer();
         $buffer_len = strlen($buffer);
         if ($buffer_len <= self::MAX_UDP_PACKAGE_SIZE) {
             stream_socket_sendto($socket, $buffer);
         } else {
             $chunk_count = ceil($buffer_len / self::MAX_UDP_PACKAGE_SIZE);
             $chunk_count = $chunk_count == 1 ? 2 : $chunk_count;
             foreach (array_chunk($data, ceil(count($data) / $chunk_count)) as $chunk_data) {
                 self::sendData($cmd, $chunk_data);
             }
         }
     }
 }
예제 #24
0
 /**
  * Listen for connections.
  */
 public function run()
 {
     while ($this->socket) {
         // Keep the server always listening.
         $client = stream_socket_accept($this->socket, -1);
         if ($client) {
             echo 'Incoming connection.' . PHP_EOL;
             $request = stream_socket_recvfrom($client, 2048);
             if ($request) {
                 echo 'Request: ' . PHP_EOL . $request;
                 // Send the handshake.
                 stream_socket_sendto($client, $this->dohandshake($request));
                 // And send the information requested.
                 // @todo: fetch the information based on the getResource().
                 stream_socket_sendto($client, "<xml>Hey human</xml>");
             }
             // And close the client.
             fclose($client);
         } else {
             exit;
         }
     }
 }
예제 #25
0
 /**
  * 向客户端socket写数据
  * @param resource $fd
  * @param string $bin_data
  */
 public function tcpWriteToClient($fd)
 {
     if (empty($this->connections[$fd])) {
         $this->notice("tcpWriteToClient \$this->connections[{$fd}] is null");
         return false;
     }
     $send_len = @stream_socket_sendto($this->connections[$fd], $this->sendBuffers[$fd]);
     if ($send_len === strlen($this->sendBuffers[$fd])) {
         if (!$this->isPersistentConnection) {
             return $this->closeClient($fd);
         }
         $this->event->del($this->connections[$fd], BaseEvent::EV_WRITE);
         return;
     }
     if ($send_len > 0) {
         $this->sendBuffers[$fd] = substr($this->sendBuffers[$fd], $send_len);
     }
 }
예제 #26
0
 /**
  * Writes data to the stream.
  *
  * @param  string $data
  * @return void
  */
 public function send($data)
 {
     $this->connect();
     @stream_socket_sendto($this->stream, $data);
     Signal::getInstance()->emit(strtolower($this->getAdapterType()) . "DataSend", $data);
 }
예제 #27
0
파일: Gateway.php 프로젝트: medz/thinksns-4
 /**
  * 发送数据到网关
  * @param string $address
  * @param string $buffer
  */
 protected static function sendToGateway($address, $gateway_data)
 {
     // 有$businessWorker说明是workerman环境,使用$businessWorker发送数据
     if (self::$businessWorker) {
         if (!isset(self::$businessWorker->gatewayConnections[$address])) {
             return false;
         }
         return self::$businessWorker->gatewayConnections[$address]->send($gateway_data);
     }
     // 非workerman环境,使用udp发送数据
     $gateway_buffer = GatewayProtocol::encode($gateway_data);
     $client = stream_socket_client("udp://{$address}", $errno, $errmsg);
     return strlen($gateway_buffer) == stream_socket_sendto($client, $gateway_buffer);
 }
예제 #28
0
 /**
  * 发送数据到网关
  * @param string $address
  * @param string $buffer
  */
 protected static function sendToGateway($address, $buffer)
 {
     // 有$businessWorker说明是workerman环境,使用$businessWorker发送数据
     if (self::$businessWorker) {
         $connections = self::$businessWorker->getGatewayConnections();
         if (!isset($connections[$address])) {
             throw new \Exception("sendToGateway({$address}, \$buffer) fail \$connections:" . var_export($connections, true));
         }
         return self::$businessWorker->sendToClient($buffer, $connections[$address]);
     }
     // 非workerman环境,使用udp发送数据
     $client = stream_socket_client("udp://{$address}", $errno, $errmsg);
     return strlen($buffer) == stream_socket_sendto($client, $buffer);
 }
예제 #29
0
파일: ext_stream.php 프로젝트: afaltz/hhvm
function test_stream_socket_sendto_issue324()
{
    list($port, $address, $server) = retry_bind_server();
    $client = stream_socket_client($address);
    $s = stream_socket_accept($server);
    $text = "testing";
    VERIFY(stream_socket_sendto($client, $text, 0, ''));
    $buffer = stream_socket_recvfrom($s, 100);
    VS($buffer, $text);
}
예제 #30
0
파일: Pool.php 프로젝트: pwhelan/randr
 private function NewWorkerUnit()
 {
     $this->pool[] = new Unit(true, ['onFork' => function ($worker) {
         $worker->on('finish', function ($status) {
             $rc = stream_socket_sendto($this->sockets[1], pack("NN", getmypid(), $status) . str_repeat("A", 512 - 8));
             fflush($this->sockets[1]);
             if ($rc != 512) {
                 print "UH OH!\n";
             }
         });
     }, 'ttl' => $this->worker_ttl]);
 }