• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP stream_socket_sendto函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中stream_socket_sendto函数的典型用法代码示例。如果您正苦于以下问题:PHP stream_socket_sendto函数的具体用法?PHP stream_socket_sendto怎么用?PHP stream_socket_sendto使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了stream_socket_sendto函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。

示例1: query

    public function query($text)
    {
        $head = <<<_HEADER_
<?xml version="1.0" ?>
<wordsegmentation version="0.1">
<option showcategory="1" />
<authentication username="{$this->user}" password="{$this->passwd}" />
<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;
        }
    }
开发者ID:balduran,项目名称:CKIP-interface-for-PHP,代码行数:32,代码来源:CKIP.php


示例2: processMessage

 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);
 }
开发者ID:ddelnano,项目名称:dredd-hooks-php,代码行数:27,代码来源:Server.php


示例3: _send_udp

 /**
  * 发送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);
     }
 }
开发者ID:google2013,项目名称:StatsCenter,代码行数:12,代码来源:StatsCenter.php


示例4: close_moniter

 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));
     }
 }
开发者ID:sniperwzq,项目名称:moniter-client,代码行数:30,代码来源:setmoniter.php


示例5: write

 /**
  * {@inheritdoc}
  */
 public function write($string)
 {
     if (!$this->isWritable()) {
         throw new RuntimeException("Stream is not writable");
     }
     return stream_socket_sendto($this->getContext(), $string);
 }
开发者ID:Talesoft,项目名称:tale-net,代码行数:10,代码来源:SocketBase.php


示例6: write

 /**
  * {@inheritdoc}
  */
 public function write($data = null)
 {
     if (isset($this->stream) === false) {
         $this->createStream();
     }
     @stream_socket_sendto($this->stream, $data);
     return true;
 }
开发者ID:influxdb,项目名称:influxdb-php,代码行数:11,代码来源:UDP.php


示例7: sendData

 /**
  * 发送数据给统计系统
  * @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);
 }
开发者ID:shitfSign,项目名称:workerman-game,代码行数:14,代码来源:StatisticClient.php


示例8: write

 /**
  * 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;
 }
开发者ID:greggcz,项目名称:librenms,代码行数:16,代码来源:UDP.php


示例9: sendData

 /**
  * 发送数据给统计系统
  * @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);
 }
开发者ID:smalleyes,项目名称:statistics,代码行数:15,代码来源:StatisticClient.php


示例10: request

 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.");
     }
 }
开发者ID:xiaoyjy,项目名称:retry,代码行数:11,代码来源:hb.php


示例11: run

 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");
 }
开发者ID:jxw7733,项目名称:zphpdemo,代码行数:11,代码来源:ReactThread.php


示例12: send

 /**
  * 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);
 }
开发者ID:walkor,项目名称:workerman,代码行数:18,代码来源:UdpConnection.php


示例13: pingUdp

 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}");
     }
 }
开发者ID:microcosmx,项目名称:experiments,代码行数:12,代码来源:queuemonitor.php


示例14: add

    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);
    }
开发者ID:jplambert,项目名称:phrrs,代码行数:12,代码来源:SocketInterface.php


示例15: writeSync

 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);
     }
 }
开发者ID:RogerWaters,项目名称:react-thread-pool,代码行数:13,代码来源:ThreadConnection.php


示例16: write

 /**
  * 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;
 }
开发者ID:Jvbzephir,项目名称:zebra_http_server,代码行数:17,代码来源:Request.php


示例17: waitChild

 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;
     }
 }
开发者ID:tiagobutzke,项目名称:phparallel,代码行数:14,代码来源:SharedThread.php


示例18: handleSend

 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');
     }
 }
开发者ID:hanlicun,项目名称:PhpCoap,代码行数:16,代码来源:PacketBuffer.php


示例19: pollData

 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;
 }
开发者ID:anton-itscript,项目名称:WM-Web,代码行数:47,代码来源:PollingCommand.php


示例20: write

 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);
 }
开发者ID:domraider,项目名称:rxnet,代码行数:18,代码来源:Buffer.php



注:本文中的stream_socket_sendto函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP stream_socket_server函数代码示例发布时间:2022-05-23
下一篇:
PHP stream_socket_recvfrom函数代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap