Server启动在主进程的主线程回调此函数
在此事件之前Swoole Server已进行了如下操作
已创建了manager进程
已创建了worker子进程
已监听所有TCP/UDP端口
已监听了定时器
onStart回调中，仅允许echo、打印Log、修改进程名称。不得执行其他操作。
onWorkerStart和onStart回调是在不同进程中并行执行的，不存在先后顺序。
@param \swoole\server $server
359172
public function __start(\swoole\Server $server) {
        $pid = posix_getpid();
        file_put_contents($this->options['enable_pid'], $pid);

        if(method_exists($this->callback,'start')) {
            $this->callback->start($server);
        }
    }
632104
public function onSwooleWorkerStart($serv, $workerId)
    {
        parent::onSwooleWorkerStart($serv, $workerId);
        if (!$this->isTaskWorker()) {
            $this->whoops = new Run();
            $this->whoops->writeToOutput(false);
            $this->whoops->allowQuit(false);
            $handler = new SDPageHandler();
            $handler->setPageTitle("出现错误了");
            $this->whoops->pushHandler($handler);
            $this->setTemplateEngine();
        }
    }
700081
public function doPacket(swoole_server $server, $data, $clientInfo)
    {
        $data = Json::decode($data);
        $request = new ServerRequest($data['method'], $data['path']);
        if (isset($data['args'])) {
            if ('GET' === $request->getMethod()) {
                $request->withQueryParams($data['args']);
            } else {
                $request->withParsedBody($data['args']);
            }
        }
        $response = app()->handleRequest($request);
        $server->sendto($clientInfo['address'], $clientInfo['port'], (string) $response->getBody());
        app()->shutdown($request, $response);

        return 0;
    }
123193
public function setServer($server)
    {
        if (is_a($server,'Cetera\\Server')) {
            $this->_server = $server;
            return $this;
        }
        if (is_int($server)) {
            $this->_server = Server::getById($server);
            return $this;        
        }
    }
351951
public function onManagerStart(SwServer $server)
    {
        // {{
        $this->setRunUser();
        $this->setProcessName('manager');
        // }}

        // {{ log
        $this->get('logger')->info('启动 Manager 进程', [
            'pid' => $server->manager_pid
        ]);
        // }}
    }
766767
public function onWorkerStart($serv, $workerId)
    {
        // Worker类型
        if (!$this->isTaskWorker()) {
            if ($workerId !== null) {
                $this->processType = Macro::PROCESS_WORKER;
                getInstance()->sysTimers[] = swoole_timer_tick(2000, function ($timerId) {
                    $this->statistics();
                });
            }
        } else {
            $this->processType = Macro::PROCESS_TASKER;
        }

        parent::onWorkerStart($serv, $workerId);
        if ($this->processType == Macro::PROCESS_WORKER || $this->processType == Macro::PROCESS_TIMER) {
            $this->initAsynPools();
            $this->initRedisProxies();
            $this->initMysqlProxies();

            //注册
            $this->asynPoolManager = new AsynPoolManager(null, $this);
            $this->asynPoolManager->noEventAdd();
            foreach ($this->asynPools as $pool) {
                if ($pool) {
                    $pool->workerInit($workerId);
                    $this->asynPoolManager->registerAsyn($pool);
                }
            }

            if (!empty($this->redisProxyManager)) {
                //redis proxy监测
                getInstance()->sysTimers[] = $this->server->tick(5000, function () {
                    foreach ($this->redisProxyManager as $proxy) {
                        $proxy->check();
                    }
                });
            }

            if (!empty($this->mysqlProxyManager)) {
                // mysql proxy监测
                getInstance()->sysTimers[] = $this->server->tick(5000, function () {
                    foreach ($this->mysqlProxyManager as $proxy) {
                        $proxy->check();
                    }
                });
            }
        }
    }
1092779
public function onStart(swoole_server $server)
    {
        if (version_compare(SWOOLE_VERSION, '1.9.5', '<')) {
            file_put_contents($this->pidFile, $server->master_pid);
            $this->pid = $server->master_pid;
        }

        process_rename($this->name . ' master');

        $this->output->writeln(sprintf("Listen: <info>%s://%s:%s</info>", $this->getScheme(), $this->getHost(), $this->getPort()));
        foreach ($this->listens as $listen) {
            $this->output->writeln(sprintf(" <info> ></info> Listen: <info>%s://%s:%s</info>", $listen->getScheme(), $listen->getHost(), $listen->getPort()));
        }

        $this->output->writeln(sprintf('PID file: <info>%s</info>, PID: <info>%s</info>', $this->pidFile, $server->master_pid));
        $this->output->writeln(sprintf('Server Master[<info>%s</info>] is started', $server->master_pid), OutputInterface::VERBOSITY_DEBUG);
    }
228888
public function onManagerStart(swoole_server $server)
    {
        process_rename($this->getName() . ' manager');

        $this->console(sprintf('Server Manager[<info>%s</info>] is started', $server->manager_pid), OutputInterface::VERBOSITY_DEBUG);
    }
1289042
public function onReceive($server, $fd, $from_id, $data)
    {
        //$this->log("Connection[{$fd}] received ".strlen($data)." bytes.");
        //未连接
        if (!isset($this->connections[$fd]))
        {
            return parent::onReceive($server, $fd, $from_id, $data);
        }

        while (strlen($data) > 0 and isset($this->connections[$fd]))
        {
            //新的请求
            if (!isset($this->frame_list[$fd]))
            {
                $frame = $this->parseFrame($data);
                if ($frame === false)
                {
                    $this->log("Error Frame");
                    $this->close($fd);
                    break;
                }
                //数据完整
                if ($frame['finish'])
                {
                    $this->log("NewFrame finish. Opcode=".$frame['opcode']."|Length={$frame['length']}");
                    $this->opcodeSwitch($fd, $frame);
                }
                //数据不完整加入到缓存中
                else
                {
                    $this->frame_list[$fd] = $frame;
                }
            }
            else
            {
                $frame = &$this->frame_list[$fd];
                $frame['data'] .= $data;

                //$this->log("wait length = ".$ws['length'].'. data_length='.strlen($ws['data']));

                //数据已完整，进行处理
                if (strlen($frame['data']) >= $frame['length'])
                {
                    $frame['fin'] = 1;
                    $frame['finish'] = true;
                    $frame['data'] = substr($frame['data'], 0, $frame['length']);
                    $frame['message'] = $this->parseMessage($frame);
                    $this->opcodeSwitch($fd, $frame);
                    $data = substr($frame['data'], $frame['length']);
                }
                //数据不足，跳出循环，继续等待数据
                else
                {
                    break;
                }
            }
        }
        return true;
    }
877744
public function onFinish(SwServer $server, int $taskId, $data)
    {
        // {{
        $this->get('task')->onFinish($server, $taskId, $data);
        // }}

        // {{ log
        $this->get('logger')->info('结束任务', [
            'id' => $taskId,
            'data' => is_array($data) ? json_encode($data) : $data
        ]);
        // }}
    }
359140
public function execute(Server $server)
    {
        $cursor = $server->executeCommand($this->databaseName, $this->command, $this->createOptions());

        if (isset($this->options['typeMap'])) {
            $cursor->setTypeMap($this->options['typeMap']);
        }

        return $cursor;
    }
391720
public function initialize(DAV\Server $server)
    {
        $this->server = $server;

        $server->on('method:MKCALENDAR', [$this, 'httpMkCalendar']);
        $server->on('report', [$this, 'report']);
        $server->on('propFind', [$this, 'propFind']);
        $server->on('onHTMLActionsPanel', [$this, 'htmlActionsPanel']);
        $server->on('beforeCreateFile', [$this, 'beforeCreateFile']);
        $server->on('beforeWriteContent', [$this, 'beforeWriteContent']);
        $server->on('afterMethod:GET', [$this, 'httpAfterGET']);
        $server->on('getSupportedPrivilegeSet', [$this, 'getSupportedPrivilegeSet']);

        $server->xml->namespaceMap[self::NS_CALDAV] = 'cal';
        $server->xml->namespaceMap[self::NS_CALENDARSERVER] = 'cs';

        $server->xml->elementMap['{'.self::NS_CALDAV.'}supported-calendar-component-set'] = 'Sabre\\CalDAV\\Xml\\Property\\SupportedCalendarComponentSet';
        $server->xml->elementMap['{'.self::NS_CALDAV.'}calendar-query'] = 'Sabre\\CalDAV\\Xml\\Request\\CalendarQueryReport';
        $server->xml->elementMap['{'.self::NS_CALDAV.'}calendar-multiget'] = 'Sabre\\CalDAV\\Xml\\Request\\CalendarMultiGetReport';
        $server->xml->elementMap['{'.self::NS_CALDAV.'}free-busy-query'] = 'Sabre\\CalDAV\\Xml\\Request\\FreeBusyQueryReport';
        $server->xml->elementMap['{'.self::NS_CALDAV.'}mkcalendar'] = 'Sabre\\CalDAV\\Xml\\Request\\MkCalendar';
        $server->xml->elementMap['{'.self::NS_CALDAV.'}schedule-calendar-transp'] = 'Sabre\\CalDAV\\Xml\\Property\\ScheduleCalendarTransp';
        $server->xml->elementMap['{'.self::NS_CALDAV.'}supported-calendar-component-set'] = 'Sabre\\CalDAV\\Xml\\Property\\SupportedCalendarComponentSet';

        $server->resourceTypeMapping['\\Sabre\\CalDAV\\ICalendar'] = '{urn:ietf:params:xml:ns:caldav}calendar';

        $server->resourceTypeMapping['\\Sabre\\CalDAV\\Principal\\IProxyRead'] = '{http://calendarserver.org/ns/}calendar-proxy-read';
        $server->resourceTypeMapping['\\Sabre\\CalDAV\\Principal\\IProxyWrite'] = '{http://calendarserver.org/ns/}calendar-proxy-write';

        array_push($server->protectedProperties,
            '{'.self::NS_CALDAV.'}supported-calendar-component-set',
            '{'.self::NS_CALDAV.'}supported-calendar-data',
            '{'.self::NS_CALDAV.'}max-resource-size',
            '{'.self::NS_CALDAV.'}min-date-time',
            '{'.self::NS_CALDAV.'}max-date-time',
            '{'.self::NS_CALDAV.'}max-instances',
            '{'.self::NS_CALDAV.'}max-attendees-per-instance',
            '{'.self::NS_CALDAV.'}calendar-home-set',
            '{'.self::NS_CALDAV.'}supported-collation-set',
            '{'.self::NS_CALDAV.'}calendar-data',

            // CalendarServer extensions
            '{'.self::NS_CALENDARSERVER.'}getctag',
            '{'.self::NS_CALENDARSERVER.'}calendar-proxy-read-for',
            '{'.self::NS_CALENDARSERVER.'}calendar-proxy-write-for'
        );

        if ($aclPlugin = $server->getPlugin('acl')) {
            $aclPlugin->principalSearchPropertySet['{'.self::NS_CALDAV.'}calendar-user-address-set'] = 'Calendar address';
        }
    }
1216562
public function __shutdown(\swoole\Server $server) {
        $path = $this->options['enable_pid'];
        file_exists($path) and unlink($path);

        if(method_exists($this->callback,'shutdown')) {
            $this->callback->shutdown($server);
        }
    }
342375
function runServer(cb) {
  function onStdOut(data) {
    const time = new Date().toTimeString();
    const match = data.toString('utf8').match(RUNNING_REGEXP);

    process.stdout.write(time.replace(/.*(\d{2}:\d{2}:\d{2}).*/, '[$1] '));
    process.stdout.write(data);

    if (match) {
      server.stdout.removeListener('data', onStdOut);
      server.stdout.on('data', x => process.stdout.write(x));
      if (cb) {
        cb(null, match[1]);
      }
    }
  }

  if (server) {
    server.kill('SIGTERM');
  }

  server = cp.spawn('node', [serverPath], {
    env: Object.assign({ NODE_ENV: 'development' }, process.env),
    silent: false,
  });

  server.stdout.on('data', onStdOut);
  server.stderr.on('data', x => process.stderr.write(x));
}
504692
public function doWork(swoole_server $server, $fd, $data, $from_id)
    {
        if ('quit' === $data) {
            $server->close($fd);

            return 0;
        }
        $data = Json::decode($data);
        $request = new ServerRequest($data['method'], $data['path']);
        if (isset($data['args'])) {
            if ('GET' === $request->getMethod()) {
                $request->withQueryParams($data['args']);
            } else {
                $request->withParsedBody($data['args']);
            }
        }
        $response = app()->handleRequest($request);
        if (null !== $response->getFileDescriptor()) {
            $fd = $response->getFileDescriptor();
        }
        if (false === $server->connection_info($fd)) {
            return -1;
        }
        $server->send($fd, (string) $response->getBody());
        app()->shutdown($request, $response);

        return 0;
    }
621267
public function initialize(DAV\Server $server)
    {
        $this->server = $server;
        $this->server->on('method:GET', [$this, 'httpGetEarly'], 90);
        $this->server->on('method:GET', [$this, 'httpGet'], 200);
        $this->server->on('onHTMLActionsPanel', [$this, 'htmlActionsPanel'], 200);
        if ($this->enablePost) {
            $this->server->on('method:POST', [$this, 'httpPOST']);
        }
    }
1182524
public function listen(Server $server, SwoolePort $swoolePort = null)
    {
        if ($this->isBound()) {
            throw new LogicException('The server socket can be bound to server only once.');
        }

        if ($swoolePort == null) {
            // If the passed Swoole port is null, that means we are calling this
            // method directly, so here we need to call the server method "listen"
            // to do the actual binding.
            return $server->listen($this);
        }

        $this->server = $server;
        $this->swoolePort = $swoolePort;

        $this->swoolePort->set($this->options);

        $this->registerEventCallbacks($this->serverSocketEvents);

        $this->dispatchEvent('Bind', $server, $this);
    }