<?php define('DEBUG', 'on'); define('WEBPATH', __DIR__); /** * /vendor/autoload.php是Composer工具生成的 * shell: composer update */ require __DIR__ . '/vendor/autoload.php'; /** * Swoole框架自动载入器初始化 */ Swoole\Loader::vendor_init(); /** * 注册命名空间到自动载入器中 */ Swoole\Loader::addNameSpace('WebIM', __DIR__ . '/src/'); $config = (require __DIR__ . '/config.php'); $webim = new WebIM\Server($config); $webim->loadSetting(__DIR__ . "/swoole.ini"); //加载配置文件 /** * webim必须使用swoole扩展 */ $server = new Swoole\Network\Server($config['server']['host'], $config['server']['port']); $server->setProtocol($webim); $server->run($config['swoole']);
<?php define('DEBUG', 'on'); define("WEBPATH", realpath(__DIR__ . '/../')); require_once __DIR__ . '/../vendor/autoload.php'; Swoole\Loader::vendor_init(); Swoole\Loader::addNameSpace('WebIM', __DIR__ . '/src/'); Swoole::$php->config->setPath(__DIR__ . '/apps/configs'); $AppSvr = new Swoole\Protocol\HttpServer(); $AppSvr->loadSetting(__DIR__ . '/../swoole.ini'); //加载配置文件 $AppSvr->setDocumentRoot(__DIR__); $AppSvr->setLogger(new \Swoole\Log\EchoLog(true)); //Logger $server = new \Swoole\Network\Server('0.0.0.0', 8888); $server->setProtocol($AppSvr); $server->run(array('worker_num' => 1));
<?php require __DIR__ . '/config.php'; //require __DIR__'/phar://swoole.phar'; //Swoole\Config::$debug = true; Swoole\Error::$echo_html = false; $AppSvr = new Swoole\Protocol\AppServer(); $AppSvr->loadSetting("./swoole.ini"); //加载配置文件 $AppSvr->setAppPath(__DIR__ . '/apps/'); //设置应用所在的目录 $AppSvr->setDocumentRoot(__DIR__); $AppSvr->setLogger(new \Swoole\Log\FileLog('/tmp/swoole.log')); //Logger $server = new \Swoole\Network\Server('0.0.0.0', 9501); $server->setProtocol($AppSvr); //$server->daemonize(); //作为守护进程 $server->run(array('worker_num' => 2, 'max_request' => 1000));
function runHttpServer($host = '0.0.0.0', $port = 9501, $config = array()) { define('SWOOLE_SERVER', true); define('SWOOLE_HTTP_SERVER', true); $this->ext_http_server = $this->http = new Swoole\Http\ExtServer($config); Swoole\Network\Server::$useSwooleHttpServer = true; $server = new Swoole\Network\Server($host, $port); $server->setProtocol($this->http); $server->run($config); }
//$this->broadcast($client_id, $ws['message']); } function broadcast($client_id, $msg) { foreach ($this->connections as $clid => $info) { if ($client_id != $clid) { $this->send($clid, $msg); } } } } //require __DIR__'/phar://swoole.phar'; Swoole\Config::$debug = true; Swoole\Error::$echo_html = false; $AppSvr = new WebSocket(); $AppSvr->loadSetting(__DIR__ . "/swoole.ini"); //加载配置文件 $AppSvr->setLogger(new \Swoole\Log\EchoLog(true)); //Logger /** * 如果你没有安装swoole扩展,这里还可选择 * BlockTCP 阻塞的TCP,支持windows平台 * SelectTCP 使用select做事件循环,支持windows平台 * EventTCP 使用libevent,需要安装libevent扩展 */ $enable_ssl = false; $server = new \Swoole\Network\Server('0.0.0.0', 9443, $enable_ssl); $server->setProtocol($AppSvr); //$server->daemonize(); //作为守护进程 $server->run(array('worker_num' => 1, 'ssl_key_file' => __DIR__ . '/ssl/ssl.key', 'ssl_cert_file' => __DIR__ . '/ssl/ssl.crt'));