當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。