Hprose\Swoole\Server::__construct PHP Метод

__construct() публичный Метод

public __construct ( $uri, $mode = SWOOLE_BASE )
    public function __construct($uri, $mode = SWOOLE_BASE)
    {
        $p = parse_url($uri);
        if ($p) {
            switch (strtolower($p['scheme'])) {
                case 'ws':
                case 'wss':
                    $this->server = new \Hprose\Swoole\WebSocket\Server($uri, $mode);
                    break;
                case 'http':
                case 'https':
                    $this->server = new \Hprose\Swoole\Http\Server($uri, $mode);
                    break;
                case 'tcp':
                case 'tcp4':
                case 'tcp6':
                case 'ssl':
                case 'sslv2':
                case 'sslv3':
                case 'tls':
                case 'unix':
                    $this->server = new \Hprose\Swoole\Socket\Server($uri, $mode);
                    break;
                default:
                    throw new Exception("Can't support this scheme: {$p['scheme']}");
            }
        } else {
            throw new \Exception("Can't parse this url: " . $uri);
        }
    }

Usage Example

 /**
  * 初始化swoole服务配置
  * @param $ini_file swoole的服务启动配置文件位置
  */
 public function __construct($ini_file, $pidFile = false)
 {
     if ($pidFile) {
         $this->pidFile = $pidFile;
     }
     if (!is_file($ini_file)) {
         exit("Swoole AppServer配置文件错误({$ini_file})\n");
     }
     $config = parse_ini_file($ini_file, true);
     if (!is_array($this->config)) {
         $this->config = array();
     }
     $this->config = array_merge($this->config, $config);
     if (isset($this->config['server']['host']) && isset($this->config['server']['port'])) {
         parent::__construct($this->config['server']['host'] . ':' . $this->config['server']['port']);
     } else {
         parent::__construct(self::DEFAULT_HOST . ':' . self::DEFAULT_PORT);
     }
 }