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


PHP stream_socket_shutdown函数代码示例

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


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

示例1: run

 /**
  * Runs the server.
  * This function will block forever and never return, except if an exception is thrown during the startup of the server.
  */
 public function run()
 {
     if (ini_get('max_execution_time') != 0) {
         throw new \LogicException('PHP must have no max_execution_time in order to start a server');
     }
     if (($this->socket = stream_socket_server($this->bindAddress, $errNo, $errString)) === false) {
         throw new \RuntimeException('Could not create listening socket: ' . $errString);
     }
     do {
         $readableSockets = [$this->socket];
         $write = null;
         $except = null;
         stream_select($readableSockets, $write, $except, 5);
         foreach ($readableSockets as $socket) {
             if ($socket === $this->socket) {
                 $newSocket = stream_socket_accept($this->socket);
                 try {
                     $request = new HTTPRequestFromStream($newSocket);
                     $response = new HTTPResponseToStream($newSocket);
                     $response->setHeader('Server', 'Niysu IPC server');
                     $response->setHeader('Connection', 'close');
                     $this->niysuServer->handle($request, $response);
                     stream_socket_shutdown($newSocket, STREAM_SHUT_RDWR);
                 } catch (\Exception $e) {
                     fwrite($newSocket, 'HTTP/1.1 500 Internal Server Error' . "\r\n");
                     fwrite($newSocket, 'Server: Niysu IPC server' . "\r\n\r\n");
                     fflush($newSocket);
                     stream_socket_shutdown($newSocket, STREAM_SHUT_RDWR);
                 }
             }
         }
     } while (true);
     stream_socket_shutdown($this->socket, STREAM_SHUT_RDWR);
 }
开发者ID:tomaka17,项目名称:niysu,代码行数:38,代码来源:IPCServer.php

示例2: run

 public function run()
 {
     $client = $this->socket;
     fwrite($client, "Hello.Bye.\n");
     stream_socket_shutdown($client, STREAM_SHUT_RDWR);
     fclose($client);
 }
开发者ID:Abhishek-Ghosh,项目名称:invalid-pointer-0x00007f75ec3ff0e0,代码行数:7,代码来源:test.php

示例3: evcb_CommandEvent

 /**
  * Command Channel event callback
  * @param resorec $Socket
  * @param int $Events
  */
 public function evcb_CommandEvent($Socket, $Events)
 {
     $ClientSocketForCommand = @stream_socket_accept($this->CommandSocket);
     $Data = json_decode($aaa = @fread($ClientSocketForCommand, 4096), true);
     stream_set_blocking($ClientSocketForCommand, 0);
     @stream_socket_shutdown($ClientSocketForCommand, STREAM_SHUT_RDWR);
     @fclose($ClientSocketForCommand);
     switch ($Data['Command']) {
         case 'Report':
             file_put_contents('/tmp/xdebug/' . $this->ServerIndex, $this->ServerIndex . ':' . time() . ':' . $this->CurrentConnected . "\n");
             break;
         case 'GC':
             $this->ClientGC();
             break;
         case 'Exit':
             echo "Start Killall Client Socket!\n";
             foreach ($this->ClientData as $SockName => $Data) {
                 $this->ClientShutDown($SockName);
             }
             echo "Killed all Client Socket!\n";
             event_base_loopbreak($this->BaseEvent);
             shmop_close($this->SHM);
             break;
         case 'Push':
             $this->ServerPush($Data['Event']);
             break;
     }
 }
开发者ID:RickySu,项目名称:phpEventHttpd,代码行数:33,代码来源:EventHttpServer.class.php

示例4: handleClose

 public function handleClose()
 {
     if (is_resource($this->stream)) {
         stream_socket_shutdown($this->stream, STREAM_SHUT_RDWR);
         fclose($this->stream);
     }
 }
开发者ID:alexMaluco,项目名称:LightTable-PHP,代码行数:7,代码来源:Connection.php

示例5: onAcceptEvent

 public function onAcceptEvent($bindSocket, $events, $arg)
 {
     $bindSocketId = $arg[0];
     Debug::netEvent(get_class($this) . '::' . __METHOD__ . '(' . $bindSocketId . ') invoked.');
     // add to accept next event
     // why not use EV_PERSIST
     event_add($this->bindSocketEvPool[$bindSocketId]);
     $connSocket = stream_socket_accept($this->bindSocketPool[$bindSocketId]);
     if (!$connSocket) {
         Debug::netErrorEvent(get_class($this) . ': can not accept new TCP-socket');
         return;
     }
     stream_set_blocking($connSocket, 0);
     list($ip, $port) = explode(':', stream_socket_get_name($connSocket, true));
     $connId = daemon::getNextConnId();
     $evBuf = event_buffer_new($connSocket, array($this, 'onEvBufReadEvent'), array($this, 'onEvBufWriteEvent'), array($this, 'onEventEvent'), array($connId));
     event_buffer_base_set($evBuf, daemon::$eventBase);
     event_buffer_priority_set($evBuf, 10);
     event_buffer_watermark_set($evBuf, EV_READ, $this->evBufLowMark, $this->evBufHighMark);
     if (!event_buffer_enable($evBuf, EV_READ | EV_WRITE | EV_PERSIST)) {
         Debug::netErrorEvent(get_class($this) . '::' . __METHOD__ . ': can not set base of buffer. #' . $connId);
         //close socket
         stream_socket_shutdown($connSocket, STREAM_SHUT_RDWR);
         fclose($connSocket);
         return;
     }
     // 调试这里时,浪费了很多时间,必须注意的是,以上 event 所用的变量如果在函数中,如果没有交给其他的变量引用,在函数结束时就会销毁,
     // 造成连接直接断或者bufferevent 不能触发。晕啊晕。
     $this->connSocketPool[$connId] = $connSocket;
     $this->connEvBufPool[$connId] = $evBuf;
     $this->updateLastContact($connId);
     $this->onAccepted($connId, $ip, $port);
 }
开发者ID:ansendu,项目名称:ansio,代码行数:33,代码来源:AsyncServer.php

示例6: handle

 /**
  * Handles the request by calling the IPC server.
  *
  * This function will connect to the IPC server, send the request, and copy what the server sends back to the response.
  *
  * @param HTTPRequestInterface 		$httpRequest		The request to handle (if null, an instance of HTTPRequestGlobal)
  * @param HTTPResponseInterface 	$httpResponse		The response where to write the output (if null, an instance of HTTPResponseGlobal)
  */
 public function handle(HTTPRequestInterface $httpRequest = null, HTTPResponseInterface $httpResponse = null)
 {
     if (!$httpRequest) {
         $httpRequest = new HTTPRequestGlobal();
     }
     if (!$httpResponse) {
         $httpResponse = new HTTPResponseGlobal();
     }
     if (($this->socket = stream_socket_client($this->bindAddress, $errNo, $errString)) === false) {
         throw new \RuntimeException('Could not create client socket: ' . $errString);
     }
     // writing request line
     $toWrite = $httpRequest->getMethod() . ' ' . $httpRequest->getURL() . ' HTTP/1.1' . "\r\n";
     // TODO: HTTP version
     fwrite($this->socket, $toWrite);
     // writing headers
     foreach ($httpRequest->getHeadersList() as $header => $value) {
         $toWrite = $header . ': ' . $value . "\r\n";
         fwrite($this->socket, $toWrite);
     }
     // writing data
     $toWrite = "\r\n" . $httpRequest->getRawData();
     fwrite($this->socket, $toWrite);
     stream_socket_shutdown($this->socket, STREAM_SHUT_WR);
     fflush($this->socket);
     // reading response
     $response = HTTPResponseStream::build($httpResponse, true);
     $response->fwrite(stream_get_contents($this->socket));
     $response->fflush();
     unset($response);
     stream_socket_shutdown($this->socket, STREAM_SHUT_RDWR);
     $httpResponse->flush();
 }
开发者ID:tomaka17,项目名称:niysu,代码行数:41,代码来源:IPCClient.php

示例7: disconnect

 public function disconnect($quitMessage = null)
 {
     $this->bot->removeConnection($this);
     if ($this->socket !== null) {
         stream_socket_shutdown($this->socket, STREAM_SHUT_RDWR);
     }
     $this->socket = null;
 }
开发者ID:erebot,项目名称:erebot,代码行数:8,代码来源:Server.php

示例8: close

 public function close()
 {
     $this->log->info('closing connection: ' . $this->nodeUrl);
     stream_socket_shutdown($this->stream, STREAM_SHUT_RDWR);
     $this->stream = null;
     $this->log->info('connection closed: ' . $this->nodeUrl);
     return true;
 }
开发者ID:0x20h,项目名称:phloppy,代码行数:8,代码来源:DefaultStream.php

示例9: close

 public function close()
 {
     if ($this->_socket !== null) {
         $this->executeCommand('QUIT');
         stream_socket_shutdown($this->_socket, STREAM_SHUT_RDWR);
         $this->_socket = null;
     }
 }
开发者ID:heyanlong,项目名称:yii2-redis,代码行数:8,代码来源:Connection.php

示例10: handleClose

 public function handleClose()
 {
     if (is_resource($this->stream)) {
         // http://chat.stackoverflow.com/transcript/message/7727858#7727858
         stream_socket_shutdown($this->stream, STREAM_SHUT_RDWR);
         stream_set_blocking($this->stream, false);
         fclose($this->stream);
     }
 }
开发者ID:reactphp,项目名称:socket,代码行数:9,代码来源:Connection.php

示例11: close

 /**
  * Close the connection.
  */
 public function close()
 {
     $meta_data = stream_get_meta_data($this->resource);
     $this->extra = $meta_data['wrapper_data'];
     stream_socket_shutdown($this->resource, STREAM_SHUT_RDWR);
     // Don't allow any more reads/writes
     stream_get_contents($this->resource);
     // Clear any stuff on the socket, otherwise it will stay open
     fclose($this->resource);
     $this->resource = null;
 }
开发者ID:jasny,项目名称:Q,代码行数:14,代码来源:Connection.php

示例12: shutdown

 public function shutdown($read, $write)
 {
     $r = null;
     if (function_exists("stream_socket_shutdown")) {
         $rw = $read && $write ? 2 : ($write ? 1 : ($read ? 0 : 2));
         $r = stream_socket_shutdown($this->__s, $rw);
     } else {
         $r = fclose($this->__s);
     }
     sys_net_Socket::checkError($r, 0, "Unable to Shutdown");
 }
开发者ID:Raniratna,项目名称:new_elearning,代码行数:11,代码来源:Socket.class.php

示例13: disconnect

 public function disconnect()
 {
     // TODO Check
     $id = $this->idCount++;
     $this->sendRaw("<presence id='{$id}' type='unavailable'></presence></stream:stream>");
     \stream_socket_shutdown($this->socket, \STREAM_SHUT_RDWR);
     // TODO Check error
     \fclose($this->socket);
     // TODO Check error
     $this->socket = null;
     $this->stanzaParser = null;
 }
开发者ID:sdrieling,项目名称:osw-RPOSWWebClient,代码行数:12,代码来源:XMPP.php

示例14: close

 public function close()
 {
     echo "closed!\n";
     $this->closed = true;
     if (is_resource($this->getProperSocket())) {
         stream_socket_shutdown($this->getProperSocket(), STREAM_SHUT_RDWR);
         //This causes weird crashes. Let's just not close them.
         //@fclose($this->getProperSocket());
     }
     $this->socket = false;
     $this->rawSocket = false;
 }
开发者ID:johnvandeweghe,项目名称:JohnNet,代码行数:12,代码来源:Connection.php

示例15: run

 public function run()
 {
     if (!($ipcSocket = @stream_socket_client($this->ipcUri, $errno, $errstr, 5))) {
         throw new \RuntimeException(sprintf("Failed connecting to IPC server: (%d) %s", $errno, $errstr));
     }
     stream_set_write_buffer($ipcSocket, 0);
     stream_socket_shutdown($ipcSocket, STREAM_SHUT_RD);
     $openMsg = $this->getThreadId() . "\n";
     if (@fwrite($ipcSocket, $openMsg) !== strlen($openMsg)) {
         throw new \RuntimeException("Failed writing open message to IPC server");
     }
     $this->ipcSocket = $ipcSocket;
 }
开发者ID:xingcuntian,项目名称:thread,代码行数:13,代码来源:Thread.php


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