初始化各种连接池
@throws \Server\CoreBase\SwooleException
1990
protected function initAsynPools()
    {
        if ($this->config->get('redis.enable', true)) {
            get_instance()->addAsynPool('redisPool', new RedisAsynPool($this->config, $this->config->get('redis.active')));
        }
        if ($this->config->get('mysql.enable', true)) {
            get_instance()->addAsynPool('mysqlPool', new MysqlAsynPool($this->config, $this->config->get('mysql.active')));
        }
    }
315107
protected function createServer(): void
    {
        $server = null;
        $opts   = $this->serverSettings;

        $host = $opts['host'];
        $port = $opts['port'];
        $mode = $opts['mode'] === self::MODE_BASE ? SWOOLE_BASE : SWOOLE_PROCESS;
        $type = \strtolower($opts['type']);

        $protoEvents = self::$swooleProtocolEvents[self::PROTOCOL_HTTP];

        // create swoole server
        // 使用SSL必须在编译swoole时加入--enable-openssl选项,并且配置证书文件
        switch ($type) {
            case self::PROTOCOL_TCP:
                $server      = new Server($host, $port, $mode, SWOOLE_SOCK_TCP);
                $protoEvents = self::$swooleProtocolEvents[self::PROTOCOL_TCP];
                break;

            case self::PROTOCOL_UDP:
                $server      = new Server($host, $port, $mode, SWOOLE_SOCK_UDP);
                $protoEvents = self::$swooleProtocolEvents[self::PROTOCOL_TCP];
                break;

            case self::PROTOCOL_HTTP:
                $server = new HttpServer($host, $port, $mode);
                break;

            case self::PROTOCOL_HTTPS:
                $this->checkEnvWhenEnableSSL();
                $server = new HttpServer($host, $port, $mode, SWOOLE_SOCK_TCP | SWOOLE_SSL);
                break;

            case self::PROTOCOL_RDS:
                $server      = new RedisServer($host, $port, $mode);
                $protoEvents = self::$swooleProtocolEvents[self::PROTOCOL_RDS];
                break;

            case self::PROTOCOL_WS:
                $server      = new WebSocketServer($host, $port, $mode);
                $protoEvents = self::$swooleProtocolEvents[self::PROTOCOL_WS];
                break;

            case self::PROTOCOL_WSS:
                $this->checkEnvWhenEnableSSL();
                $server      = new WebSocketServer($host, $port, $mode, SWOOLE_SOCK_TCP | SWOOLE_SSL);
                $protoEvents = self::$swooleProtocolEvents[self::PROTOCOL_WS];
                break;

            default:
                $supportedProtocol = implode(',', $this->getSupportedProtocols());
                Show::error("The socket protocol <bold>$type</bold> is not supported. Allow: $supportedProtocol", 1);
                break;
        }

        $this->server = $server;
        $this->server->set($this->swooleSettings);

        $this->log("The main server was created successfully. Listening on <cyan>$type://{$host}:{$port}</cyan>");
        $this->setSwooleEvents($protoEvents);
    }
856660
final public function delete()
    {
        if (!$this->DB) {
            throw  new Exception('您还没有连接数据库', Exception::CODE_DATABASE_ERROR);
        }
        $sql = "delete from " . $this->getTable() . " ";
        $where = $this->buildWhere();
        //条件判断
        //没有外部条件的时候查询当前对象是否有查询过的模型
        if (!$where && $this->isfind) {
            $this->where($this->pk, '=', $this->pkval);
            $where = $this->buildWhere();
        }
        if (!$where) {
            throw new \Error('删除全部数据请使用truncate方法', Exception::CODE_DATABASE_ERROR);
        }
        $sql .= $where;
        $this->sql = $sql;
        /**
         * 只获取sql
         */
        if ($this->justSql) {
            return true;
        }
        $ret = $this->DB->execute($sql);
        $this->resetCon();
        return $ret;
    }
838078
final public function execute()
	{
		if ($this->hadException()) {
			$this->setExceptionResponse($this->exception);
			return null;
		}

		$pageExtension = $this->container->getTemplating()->getExtension('supraPage');
		/* @var $pageExtension PageExtension */
		$pageExtension->setBlockExecutionContext(new BlockExecutionContext($this, $this->request));

		try {
			$this->doExecute();
		} catch (\Exception $e) {
			$this->exception = $e;
			$this->setExceptionResponse($e);
		}
	}
247694
public function coroutineExecute($path, callable $set = null)
    {
        if (empty($this->baseUrl)) {
            throw new SwooleException('httpClient not set baseUrl!');
        }
        $data = $this->toArray();
        $data['path'] = $path;
        $data['callMethod'] = 'execute';
        $this->reset();
        return Pool::getInstance()->get(HttpClientRequestCoroutine::class)->init($this->pool, $data, $set);
    }
64823
protected function open()
    {
        if (null === $this->_pdo) {
            if (empty($this->dsn)) {
                throw new Exception('数据库连接串"dsn"不能为空', 101300101);
            }
            try {
                Timer::begin('db-connect');

                $this->_pdo = $this->createPdoInstance();
                $this->initConnection($this->_pdo);
                $this->_active = true;

                $this->pushLog('connect-db', [
                    'lastTime' => Timer::end('db-connect'),
                ]);
            } catch (\PDOException $e) {
                if (APP_DEBUG) {
                    $err_msg = '数据库连接失败: (' . $e->getCode() . ')' . $e->getMessage();
                } else {
                    $err_msg = '数据库连接失败.(' . $e->getCode() . ')';
                }
                throw new Exception($err_msg, 101300102, $e->errorInfo);
            }
        }
    }
324736
public function commit()
    {
        if ($this->_active && $this->_db->getActive()) {
            $this->_db->getPdoInstance()->commit();
            $this->_active = false;
        } else {
            throw new Exception('"Transaction"尚属未激活状态，不能执行"commit"和"rollback"操作', 101300601);
        }
    }
1121956
public function start() {
        #设置DEBUG引导程序
        (new This7Debug())->bootstrap();
        #设置配置文件
        This7Config::defineConst();
        #获取驱动列表
        $this->drives = $this->getDeviceList(VENDOR_DIR . DS . 'this7');
        #自动加载类
        spl_autoload_register(array($this, 'autoload'));
        #设置静态化
        staticize::setApplication($this);
        #绑定核心驱动
        $this->bindDrives();
        #启动路由
        routes::start();
    }
28160
public function run() {

		try {
			
			//初始化
			$this->init();

			//触发uri路由
			$this->make('router')->dispatch();

			//reset GET
			$_GET = $this->make('router')->getQueryArray();
			foreach ($_GET as $ik => $iv) {
				if (is_string($ik)) {
					$_REQUEST[$ik] = $iv;
				}
			}

			$this->runControllerAction();

			//结束
			$this->finish(0);

		} catch (\Exception $exception) {
			
			if ($this->currentController == null) {
				$this->currentController = new Controller($this, ''); //默认的controller
			}
			
			//触发事件
			$this->eventDispatcher->dispatchEvent(new \Fasim\Event\ExceptionEvent(\Fasim\Event\Event::$EXCEPTION, $exception));

			$config = $this->make('config');
			$view = $this->currentController->getView();
			$view->getLoader()->setPaths([ FS_PATH . 'View' ]);


			$debug = $this->make('config')->get('debug') === true;
			$traceString = str_replace("\n", "<br />\n", $traceString);
			$error = [
				'code' => $exception->getCode(),
				'message' => $exception->getMessage(),
				'file' => $exception->getFile(),
				'line' => $exception->getLine(),
				'trace' => $exception->getTrace()
			];
			$data = [
				'error' => $error,
				'debug' => $debug
			];
			
			if (file_exists(FS_PATH . 'View' . DIRECTORY_SEPARATOR . 'error' . $exception->getCode() . '.html')) {
				echo $view->render('error' . $exception->getCode() . '.html', $data);
			} else {
				echo $view->render('error500.html', $data);
			}
		
			//结束
			$this->finish(-1);
		}
	}
777904
public function udpClient()
    {
        $this->writeln('Starting demo swoole udp client...');

        $client = new TcpClient(SWOOLE_SOCK_UDP, SWOOLE_SOCK_ASYNC);

        $client->on(
            'connect', function ($cli) {
                //发送数据中不能包含'\r\n\r\n'
                $cli->send(JsonHelper::encode(['handler' => SwooleTcpJob::class]) . self::EOF);
            }
        );
        $client->on(
            'receive', function ($cli, $data) {
                $this->writeln('Received: '.$data);
            }
        );
        $client->on(
            'error', function ($cli) {
                $this->writeln('Connect failed');
            }
        );
        $client->on(
            "close", function ($cli) {
                $this->writeln('Connection close');
            }
        );

        $client->connect(
            $this->swooleConfig['udp']['host'] ?? self::DEFAULT_SWOOLE_HOST,
            $this->swooleConfig['udp']['port'] ?? self::DEFAULT_SWOOLE_PORT,
            $this->swooleConfig['udp']['timeout'] ?? self::DEFAULT_SWOOLE_TIMEOUT
        );
    }
470842
public function handleClientData($data)
    {
        $this->client_data = $data;
        if (isset($this->client_data->controller_name) && isset($this->client_data->method_name)) {
            return $this->client_data;
        } else {
            throw new SwooleException('route 数据缺少必要字段');
        }

    }
195618
public function run()
	{
		if( isset( $this->config['task_list'] ) && !empty( $this->config['task_list'] ) ){
			$task_list            = $this->config['task_list'];
			$cronLastExecTimeList = [];
			// 定时执行
			ServerManager::getInstance()->getServer()->tick( $this->config['loop_time'] * 1000, function() use ( &$task_list, &$cronLastExecTimeList ){
				// 分别执行
				foreach( $task_list as $name => $option ){
					try{
						// 是到期需执行 当前时间 > 最后一次时间 + 间隔时间
						$last_time     = isset( $cronLastExecTimeList[$name] ) ? $cronLastExecTimeList[$name] : 0;
						$current_time  = time();
						$interval_time = ceil( $option['interval_time'] );

						if( $current_time > ($last_time + $interval_time) ){
							// 设置最后一次执行时间 不可等任务执行完毕后再设置时间，因为会阻塞导致每秒进行一次
							$cronLastExecTimeList[$name] = $current_time;
							// 检测是否可执行
							if( \ezswoole\Cron::checkTask( $name, $option ) === true ){
								\EasySwoole\Core\Swoole\Task\TaskManager::async( function() use ( $name, $option ){
									\ezswoole\Cron::exec( $name, $option );
									return true;
								} );
							} else{
								// 删除该任务
								unset( $task_list[$name] );
							}
						}
					} catch( \Exception $e ){
						\EasySwoole\EasySwoole\Logger::getInstance()->log($e->getTraceAsString(),'error');
					}
				}
			} );
		}
		return true;
	}
258574
public function beforeSwooleStart()
    {
        parent::beforeSwooleStart();
        //创建task用的taskid
        $this->task_atomic = new \swoole_atomic(0);
        //创建task用的id->pid共享内存表不至于同时超过1024个任务吧
        $this->tid_pid_table = new \swoole_table(1024);
        $this->tid_pid_table->column('pid', \swoole_table::TYPE_INT, 8);
        $this->tid_pid_table->column('des', \swoole_table::TYPE_STRING, 100);
        $this->tid_pid_table->column('start_time', \swoole_table::TYPE_INT, 8);
        $this->tid_pid_table->create();
        //创建task用的锁
        $this->task_lock = new \swoole_lock(SWOOLE_MUTEX);
        //开启用户进程
        $this->startProcess();
        //开启一个UDP用于发graylog
        GrayLogHelp::init();
        //开启Cluster端口
        ClusterHelp::getInstance()->buildPort();
        //Timer
        Timer::init();
        //init锁
        $this->initLock = new \swoole_lock(SWOOLE_RWLOCK);
        //reload锁
        for ($i = 0; $i < $this->worker_num; ++$i) {
            $lock = new \swoole_lock(SWOOLE_MUTEX);
            $this->reloadLockMap[$i] = $lock;
        }
    }
159640
protected function bindSwooleEvents(SwServer $swoole, string $protocolName): SwServer
    {
        // {{ 初始化 Swoole Server 事件
        $events = [
            'Start'         => 'onMasterStart',
            'Shutdown'      => 'onMasterStop',
            'ManagerStart'  => 'onManagerStart',
            'WorkerStart'   => 'onWorkerStart',
            'WorkerStop'    => 'onWorkerStop',
            'WorkerError'   => 'onWorkerError',
            'WorkerExit'    => 'onWorkerExit',
            'PipeMessage'   => 'onPipeMessage',
            'Connect'       => 'onConnect',
            'Close'         => 'onClose',
            'Receive'       => 'onReceive',
        ];

        array_walk($events, function ($handler, $event) use ($swoole) {
            $swoole->on($event, [$this, $handler]);
        });

        unset($events);

        switch ($protocolName) {
            // HTTP Server
            case Protocol::HTTP:
                $swoole->on('Request', [$this, 'onRequest']);
                break;

            // UDP Server
            case Protocol::UDP:
                $swoole->on('Packet', [$this, 'onPacket']);
                break;

            // WebSocket Server
            case Protocol::WEBSOCKET:
                $swoole->on('Open', [$this, 'onOpen']);
                $swoole->on('HandShake', [$this, 'onHandShake']);
                $swoole->on('Message', [$this, 'onMessage']);
                break;
        }

        $tasks = isset($swoole->setting['task_worker_num']) ?
                (int) $swoole->setting['task_worker_num'] :
                0;

        if ($tasks > 0) {
            $swoole->on('Task', [$this, 'onTask']);
            $swoole->on('Finish', [$this, 'onFinish']);
        }

        unset($tasks);
        // }}

        return $swoole;
    }
941129
public function execute() {
        if(is_null($this->client)) {
            $this->client = $this->getConnection();
        }
        if(is_null($this->query)) {
            throw new Exception('No query');
        }

        list($query_data, $meta) = $this->constructQuery($this->source, $this->query, $this->aggs, $this->post_query, $this->settings);

        $results_set = $this->query($query_data, $meta);
        $results = $this->processResults($results_set, $meta);
        $results = $this->postProcessResults($this->post_query, $results, $meta);

        return $results;
    }
431832
protected function wait()
    {
        $timer          = 0;
        $timeout        = $this->getWaitTimeout();
        $interval       = $this->checkInterval;
        $intervalSecond = $this->checkInterval / 1000;

        while ($timer <= $timeout) {
            // 等到了可用的空闲资源
            if ($res = $this->getFreeQueue()->pop()) {
                return $res;
            }

            $timer += $interval;
            // 无空闲资源可用， 进入等待状态
            Coroutine::sleep($intervalSecond);
        }

        throw new \RuntimeException("No resources available. Waiting timeout($timeout ms) for get resource.");
    }
1311668
public function execute()
    {
        $this->_setOptions();

        $sResponse = $this->_execute();
        $this->_saveStatusCode();

        $iCurlErrorNumber = $this->_getErrorNumber();

        $this->_close();

        if ($iCurlErrorNumber) {
            $host = $this->getUrl();
            $parameters = http_build_query($this->getParameters(), "", "&");
            $message = $this->_getErrorMessage($iCurlErrorNumber);
            throw new Exception("cURL failed with message '$message' when calling '$host?$parameters'");
        }

        return $sResponse;
    }