当前位置: 首页>>代码示例>>PHP>>正文


PHP Worker::log方法代码示例

本文整理汇总了PHP中Workerman\Worker::log方法的典型用法代码示例。如果您正苦于以下问题:PHP Worker::log方法的具体用法?PHP Worker::log怎么用?PHP Worker::log使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Workerman\Worker的用法示例。


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

示例1: dealHandshake

 /**
  * Websocket handshake.
  *
  * @param string                              $buffer
  * @param \Workerman\Connection\TcpConnection $connection
  * @return int
  */
 protected static function dealHandshake($buffer, $connection)
 {
     // HTTP protocol.
     if (0 === strpos($buffer, 'GET')) {
         // Find \r\n\r\n.
         $heder_end_pos = strpos($buffer, "\r\n\r\n");
         if (!$heder_end_pos) {
             return 0;
         }
         $header_length = $heder_end_pos + 4;
         // Get Sec-WebSocket-Key.
         $Sec_WebSocket_Key = '';
         if (preg_match("/Sec-WebSocket-Key: *(.*?)\r\n/i", $buffer, $match)) {
             $Sec_WebSocket_Key = $match[1];
         } else {
             $connection->send("HTTP/1.1 400 Bad Request\r\n\r\n<b>400 Bad Request</b><br>Sec-WebSocket-Key not found.<br>This is a WebSocket service and can not be accessed via HTTP.", true);
             $connection->close();
             return 0;
         }
         // Calculation websocket key.
         $new_key = base64_encode(sha1($Sec_WebSocket_Key . "258EAFA5-E914-47DA-95CA-C5AB0DC85B11", true));
         // Handshake response data.
         $handshake_message = "HTTP/1.1 101 Switching Protocols\r\n";
         $handshake_message .= "Upgrade: websocket\r\n";
         $handshake_message .= "Sec-WebSocket-Version: 13\r\n";
         $handshake_message .= "Connection: Upgrade\r\n";
         $handshake_message .= "Server: workerman/" . Worker::VERSION . "\r\n";
         $handshake_message .= "Sec-WebSocket-Accept: " . $new_key . "\r\n\r\n";
         // Mark handshake complete..
         $connection->websocketHandshake = true;
         // Websocket data buffer.
         $connection->websocketDataBuffer = '';
         // Current websocket frame length.
         $connection->websocketCurrentFrameLength = 0;
         // Current websocket frame data.
         $connection->websocketCurrentFrameBuffer = '';
         // Consume handshake data.
         $connection->consumeRecvBuffer($header_length);
         // Send handshake response.
         $connection->send($handshake_message, true);
         // There are data waiting to be sent.
         if (!empty($connection->tmpWebsocketData)) {
             $connection->send($connection->tmpWebsocketData, true);
             $connection->tmpWebsocketData = '';
         }
         // blob or arraybuffer
         if (empty($connection->websocketType)) {
             $connection->websocketType = self::BINARY_TYPE_BLOB;
         }
         // Try to emit onWebSocketConnect callback.
         if (isset($connection->onWebSocketConnect)) {
             self::parseHttpHeader($buffer);
             try {
                 call_user_func($connection->onWebSocketConnect, $connection, $buffer);
             } catch (\Exception $e) {
                 Worker::log($e);
                 exit(250);
             } catch (\Error $e) {
                 Worker::log($e);
                 exit(250);
             }
             if (!empty($_SESSION) && class_exists('\\GatewayWorker\\Lib\\Context')) {
                 $connection->session = \GatewayWorker\Lib\Context::sessionEncode($_SESSION);
             }
             $_GET = $_SERVER = $_SESSION = $_COOKIE = array();
         }
         if (strlen($buffer) > $header_length) {
             return self::input(substr($buffer, $header_length), $connection);
         }
         return 0;
     } elseif (0 === strpos($buffer, '<polic')) {
         $policy_xml = '<?xml version="1.0"?><cross-domain-policy><site-control permitted-cross-domain-policies="all"/><allow-access-from domain="*" to-ports="*"/></cross-domain-policy>' . "";
         $connection->send($policy_xml, true);
         $connection->consumeRecvBuffer(strlen($buffer));
         return 0;
     }
     // Bad websocket handshake request.
     $connection->send("HTTP/1.1 400 Bad Request\r\n\r\n<b>400 Bad Request</b><br>Invalid handshake data for websocket. ", true);
     $connection->close();
     return 0;
 }
开发者ID:amlun,项目名称:Workerman,代码行数:88,代码来源:Websocket.php

示例2: checkConnection

 /**
  * Check connection is successfully established or faild.
  *
  * @param resource $socket
  * @return void
  */
 public function checkConnection($socket)
 {
     // Check socket state.
     if ($address = stream_socket_get_name($socket, true)) {
         // Remove write listener.
         Worker::$globalEvent->del($socket, EventInterface::EV_WRITE);
         // Nonblocking.
         stream_set_blocking($socket, 0);
         stream_set_read_buffer($socket, 0);
         // Try to open keepalive for tcp and disable Nagle algorithm.
         if (function_exists('socket_import_stream') && $this->transport === 'tcp') {
             $raw_socket = socket_import_stream($socket);
             socket_set_option($raw_socket, SOL_SOCKET, SO_KEEPALIVE, 1);
             socket_set_option($raw_socket, SOL_TCP, TCP_NODELAY, 1);
         }
         // Register a listener waiting read event.
         Worker::$globalEvent->add($socket, EventInterface::EV_READ, array($this, 'baseRead'));
         // There are some data waiting to send.
         if ($this->_sendBuffer) {
             Worker::$globalEvent->add($socket, EventInterface::EV_WRITE, array($this, 'baseWrite'));
         }
         $this->_status = self::STATUS_ESTABLISH;
         $this->_remoteAddress = $address;
         // Try to emit onConnect callback.
         if ($this->onConnect) {
             try {
                 call_user_func($this->onConnect, $this);
             } catch (\Exception $e) {
                 Worker::log($e);
                 exit(250);
             } catch (\Error $e) {
                 Worker::log($e);
                 exit(250);
             }
         }
         // Try to emit protocol::onConnect
         if (method_exists($this->protocol, 'onConnect')) {
             try {
                 call_user_func(array($this->protocol, 'onConnect'), $this);
             } catch (\Exception $e) {
                 Worker::log($e);
                 exit(250);
             } catch (\Error $e) {
                 Worker::log($e);
                 exit(250);
             }
         }
     } else {
         // Connection failed.
         $this->emitError(WORKERMAN_CONNECT_FAIL, 'connect ' . $this->_remoteAddress . ' fail after ' . round(microtime(true) - $this->_connectStartTime, 4) . ' seconds');
         if ($this->_status === self::STATUS_CLOSING) {
             $this->destroy();
         }
         if ($this->_status === self::STATUS_CLOSED) {
             $this->onConnect = null;
         }
     }
 }
开发者ID:amlun,项目名称:Workerman,代码行数:64,代码来源:AsyncTcpConnection.php

示例3: timerCallback

 /**
  * Timer callback.
  *
  * @param mixed $_null1
  * @param int   $_null2
  * @param mixed $timer_id
  */
 protected function timerCallback($_null1, $_null2, $timer_id)
 {
     if ($this->_eventTimer[$timer_id][3] === self::EV_TIMER) {
         event_add($this->_eventTimer[$timer_id][2], $this->_eventTimer[$timer_id][4]);
     }
     try {
         call_user_func_array($this->_eventTimer[$timer_id][0], $this->_eventTimer[$timer_id][1]);
     } catch (\Exception $e) {
         Worker::log($e);
         exit(250);
     } catch (\Error $e) {
         Worker::log($e);
         exit(250);
     }
     if (isset($this->_eventTimer[$timer_id]) && $this->_eventTimer[$timer_id][3] === self::EV_TIMER_ONCE) {
         $this->del($timer_id, self::EV_TIMER_ONCE);
     }
 }
开发者ID:walkor,项目名称:workerman,代码行数:25,代码来源:Libevent.php

示例4: destroy

 /**
  * Destroy connection.
  *
  * @return void
  */
 public function destroy()
 {
     // Avoid repeated calls.
     if ($this->_status === self::STATUS_CLOSED) {
         return;
     }
     // Remove event listener.
     Worker::$globalEvent->del($this->_socket, EventInterface::EV_READ);
     Worker::$globalEvent->del($this->_socket, EventInterface::EV_WRITE);
     // Close socket.
     @fclose($this->_socket);
     // Remove from worker->connections.
     if ($this->worker) {
         unset($this->worker->connections[$this->_id]);
     }
     $this->_status = self::STATUS_CLOSED;
     // Try to emit onClose callback.
     if ($this->onClose) {
         try {
             call_user_func($this->onClose, $this);
         } catch (\Exception $e) {
             Worker::log($e);
             exit(250);
         } catch (\Error $e) {
             Worker::log($e);
             exit(250);
         }
     }
     // Try to emit protocol::onClose
     if (method_exists($this->protocol, 'onClose')) {
         try {
             call_user_func(array($this->protocol, 'onClose'), $this);
         } catch (\Exception $e) {
             Worker::log($e);
             exit(250);
         } catch (\Error $e) {
             Worker::log($e);
             exit(250);
         }
     }
     if ($this->_status === self::STATUS_CLOSED) {
         // Cleaning up the callback to avoid memory leaks.
         $this->onMessage = $this->onClose = $this->onError = $this->onBufferFull = $this->onBufferDrain = null;
     }
 }
开发者ID:amlun,项目名称:Workerman,代码行数:50,代码来源:TcpConnection.php

示例5: dealHandshake

 /**
  * Websocket handshake.
  *
  * @param string                              $buffer
  * @param \Workerman\Connection\TcpConnection $connection
  * @return int
  */
 public static function dealHandshake($buffer, $connection)
 {
     $pos = strpos($buffer, "\r\n\r\n");
     if ($pos) {
         // handshake complete
         $connection->handshakeStep = 2;
         $handshake_response_length = $pos + 4;
         // Try to emit onWebSocketConnect callback.
         if (isset($connection->onWebSocketConnect)) {
             try {
                 call_user_func($connection->onWebSocketConnect, $connection, substr($buffer, 0, $handshake_response_length));
             } catch (\Exception $e) {
                 Worker::log($e);
                 exit(250);
             } catch (\Error $e) {
                 Worker::log($e);
                 exit(250);
             }
         }
         // Headbeat.
         if (!empty($connection->websocketPingInterval)) {
             $connection->websocketPingTimer = Timer::add($connection->websocketPingInterval, function () use($connection) {
                 if (false === $connection->send(pack('H*', '8900'), true)) {
                     Timer::del($connection->websocketPingTimer);
                     $connection->websocketPingTimer = null;
                 }
             });
         }
         $connection->consumeRecvBuffer($handshake_response_length);
         if (!empty($connection->tmpWebsocketData)) {
             $connection->send($connection->tmpWebsocketData, true);
             $connection->tmpWebsocketData = '';
         }
         if (strlen($buffer) > $handshake_response_length) {
             return self::input(substr($buffer, $handshake_response_length), $connection);
         }
     }
     return 0;
 }
开发者ID:google2013,项目名称:Workerman,代码行数:46,代码来源:Ws.php

示例6: timerCallback

 /**
  * Timer callback.
  *
  * @param \EvWatcher $event
  */
 public function timerCallback($event)
 {
     $param = $event->data;
     $timer_id = $param[4];
     if ($param[2] === self::EV_TIMER_ONCE) {
         $this->_eventTimer[$timer_id]->stop();
         unset($this->_eventTimer[$timer_id]);
     }
     try {
         call_user_func_array($param[0], $param[1]);
     } catch (\Exception $e) {
         Worker::log($e);
         exit(250);
     } catch (\Error $e) {
         Worker::log($e);
         exit(250);
     }
 }
开发者ID:walkor,项目名称:workerman,代码行数:23,代码来源:Ev.php


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