Esempio n. 1
0
 /**
  * remove mysql connection
  * @param $db_sock
  */
 protected function removeConnection($db_sock)
 {
     swoole_event_del($db_sock);
     $this->idle_pool[$db_sock]['object']->close();
     unset($this->idle_pool[$db_sock]);
     $this->connection_num--;
 }
Esempio n. 2
0
function socket_onConnect($socket)
{
    $err = socket_get_option($socket, SOL_SOCKET, SO_ERROR);
    if ($err == 0) {
        echo "connect server success\n";
        swoole_event_set($socket, null, 'socket_onWrite', SWOOLE_EVENT_READ);
        socket_write($socket, "first package\n");
    } else {
        echo "connect server failed\n";
        swoole_event_del($socket);
        socket_close($socket);
    }
}
Esempio n. 3
0
File: async.php Progetto: nosun/yaf
 public function __construct()
 {
     $fp = stream_socket_client("tcp://127.0.0.1:9504", $code, $msg, 3);
     $http_request = "GET /index.html HTTP/1.1\r\n\r\n";
     fwrite($fp, $http_request);
     swoole_event_add($fp, function ($fp) {
         echo fread($fp, 8192);
         swoole_event_del($fp);
         fclose($fp);
     });
     swoole_timer_after(2000, function () {
         echo "2000ms timeout\n";
     });
     swoole_timer_tick(1000, function () {
         echo "1000ms interval\n";
     });
 }
Esempio n. 4
0
 /**
  * remove mysql connection
  * @param $db_sock
  */
 protected function removeConnection($db)
 {
     if (isset($this->work_pool[$db['socket']])) {
         #不能删除正在工作的连接
         return false;
     }
     swoole_event_del($db['socket']);
     $db['object']->close();
     if (isset($this->idle_pool[$db['socket']])) {
         unset($this->idle_pool[$db['socket']]);
     }
     $this->connection_num--;
 }
Esempio n. 5
0
<?php

$fp = stream_socket_client("tcp://127.0.0.1:9501", $errno, $errstr, 30);
fwrite($fp, "HELLO world");
swoole_event_add($fp, function ($fp) {
    echo fread($fp, 1024) . "\n";
    swoole_event_del($fp);
    fclose($fp);
});
Esempio n. 6
0
 public function pepoll($opt = 'ADD', $type = 'def', $event = SWOOLE_EVENT_READ)
 {
     $fd = $this->getFd($type);
     if ($fd === -1) {
         return false;
     }
     $readHandle = $this->getHandle('read');
     $writeHandle = $this->getHandle('write');
     if ($writeHandle === null && $readHandle === null) {
         return false;
     }
     switch ($opt) {
         case 'ADD':
             $ret = swoole_event_add($fd, $readHandle, $writeHandle, $event);
             break;
         case 'MOD':
             $ret = swoole_event_set($fd, $readHandle, $writeHandle, $event);
             break;
         case 'DEL':
             $ret = swoole_event_del($fd, $readHandle, $writeHandle, $event);
             break;
         default:
             return false;
             break;
     }
     return $ret;
 }
Esempio n. 7
0
File: Mysqli.php Progetto: vucms/aha
 /**
  * @brief 关闭数据库连接
  * @param type $dbSock
  * @return \Aha\Storage\Db\Mysqli
  */
 protected function _close($dbSock)
 {
     swoole_event_del($dbSock);
     if (isset($this->_idlePool[$dbSock])) {
         $this->_idlePool[$dbSock]['dbObj']->close();
         unset($this->_idlePool[$dbSock]);
     } elseif (isset($this->_busyPool[$dbSock])) {
         $this->_busyPool[$dbSock]['dbObj']->close();
         unset($this->_busyPool[$dbSock]);
     } else {
         echo "Mysqli Exception [_close] not found [sock] {$dbSock} " . PHP_EOL;
     }
     $this->_connectionNum--;
     return $this;
 }
Esempio n. 8
0
 /**
  * @brief 关闭数据库连接
  * @param type $dbSock
  * @return \Aha\Storage\Db\Mysqli
  */
 protected function _close($dbSock)
 {
     swoole_event_del($dbSock);
     if (isset($this->_idlePool[$dbSock])) {
         $this->_idlePool[$dbSock]['dbObj']->close();
         unset($this->_idlePool[$dbSock]);
     } elseif (isset($this->_busyPool[$dbSock])) {
         $this->_busyPool[$dbSock]['dbObj']->close();
         unset($this->_busyPool[$dbSock]);
     } else {
         \Aha\Log\Sys::log()->warning("Mysqli Exception [_close] not found [sock] {$dbSock} ");
     }
     $this->_connectionNum--;
     return $this;
 }
Esempio n. 9
0
 protected function close()
 {
     if ($this->socket) {
         if (!Server::$server->taskworker) {
             swoole_event_del($this->socket);
         }
         @fclose($this->socket);
         $this->socket = null;
     }
     # 重置任务列表
     $this->taskCallbackList = [];
 }
Esempio n. 10
0
 protected function startCommandHandler()
 {
     $sockFile = $this->runDir . "command-{$this->swoolePort}.sock";
     file_exists($sockFile) and unlink($sockFile);
     ini_set('html_errors', 0);
     if (!($this->commandServer = stream_socket_server('unix://' . $sockFile, $errNo, $errStr))) {
         // @codeCoverageIgnoreStart
         $this->cliOutput('error', "Command handler start failed: {$errStr} ({$errNo})");
     } else {
         swoole_event_add($this->commandServer, function () {
             $conn = stream_socket_accept($this->commandServer, 0);
             swoole_event_add($conn, function ($conn) {
                 $command = fread($conn, 128);
                 $result = $this->processCommand($command);
                 swoole_event_write($conn, $result);
                 swoole_event_del($conn);
             });
         });
         $this->cliOutput('info', 'Command handler started.');
     }
 }