forked from whcyc2002/swoole_framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathecho_server.php
More file actions
32 lines (29 loc) · 1005 Bytes
/
Copy pathecho_server.php
File metadata and controls
32 lines (29 loc) · 1005 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<?php
define('DEBUG', 'on');
define("WEBPATH", realpath(__DIR__ . '/../'));
require __DIR__ . '/../libs/lib_config.php';
//require __DIR__'/phar://swoole.phar';
Swoole\Config::$debug = false;
class EchoServer extends Swoole\Protocol\Base
{
function onReceive($server, $client_id, $from_id, $data)
{
$this->server->send($client_id, "Swoole: " . $data);
}
}
//设置PID文件的存储路径
Swoole\Network\Server::setPidFile(__DIR__ . '/echo_server.pid');
Swoole\Network\Server::addOption('c|config:', "要加载的配置文件");
/**
* 显示Usage界面
* php app_server.php start|stop|reload
*/
Swoole\Network\Server::start(function ($options)
{
$AppSvr = new EchoServer();
$listenHost = empty($options['host']) ? '0.0.0.0' : $options['host'];
$listenPort = empty($options['port']) ? 9501 : $options['port'];
$server = Swoole\Network\Server::autoCreate($listenHost, $listenPort);
$server->setProtocol($AppSvr);
$server->run(array('worker_num' => 1));
});