Swoole\Network\Server::autoCreate PHP Method

autoCreate() static public method

自动推断扩展支持 默认使用swoole扩展,其次是libevent,最后是select(支持windows)
static public autoCreate ( $host, $port, boolean $ssl = false ) : Server
$host
$port
$ssl boolean
return Server
    static function autoCreate($host, $port, $ssl = false)
    {
        if (class_exists('\\swoole_server', false)) {
            return new self($host, $port, $ssl);
        } elseif (function_exists('event_base_new')) {
            return new EventTCP($host, $port, $ssl);
        } else {
            return new SelectTCP($host, $port, $ssl);
        }
    }

Usage Example

Example #1
0
 static function create($ini_file = null)
 {
     $opt = getopt('m:h:p:d:');
     //mode, server or fastcgi
     if (empty($opt['m'])) {
         $opt['m'] = 'server';
     }
     //daemonize
     if (empty($opt['d'])) {
         $opt['d'] = false;
     }
     if ($opt['m'] == 'fastcgi') {
         $protocol = new Swoole\Protocol\AppFPM();
     } else {
         $protocol = new Swoole\Protocol\AppServer();
     }
     if ($ini_file) {
         $protocol->loadSetting($ini_file);
         //加载配置文件
     }
     //port
     if (!empty($opt['p'])) {
         $protocol->default_port = $opt['p'];
     } elseif (!empty($protocol->config['server']['port'])) {
         $protocol->default_port = $protocol->config['server']['port'];
     } else {
         $protocol->default_port = self::DEFAULT_PORT;
     }
     //host
     if (!empty($opt['h'])) {
         $protocol->default_host = $opt['h'];
     } elseif (!empty($protocol->config['server']['host'])) {
         $protocol->default_host = $protocol->config['server']['host'];
     } else {
         $protocol->default_host = self::DEFAULT_HOST;
     }
     $server = Swoole\Network\Server::autoCreate($protocol->default_host, $protocol->default_port);
     $server->setProtocol($protocol);
     if (!empty($protocol->config['server']['worker_num'])) {
         $server->runtimeSetting['worker_num'] = $protocol->config['server']['worker_num'];
     }
     return $protocol;
 }
All Usage Examples Of Swoole\Network\Server::autoCreate