You've already forked qlg.tsgz.moe
addons
app_download_files
extend
hyhproject
mobile
oss
static
thinkphp
upload
vendor
5ini99
composer
oss-sdk
swoole
.github
benchmark
examples
async
atomic
channel
client
coroutine
eof
event
http
http2
ipv6
length
lock
memory
mmap
multicast
mysql
namespace
php
postgresql
process
redis
runtime
server
socket_coro
ssl
table
task
timer
udp
unixsock
websocket
buffer.php
c10k.php
channel.php
client2.php
db_pool.php
get_local_ip.php
hot_update_class.php
multi_port_server.php
mysql_proxy_server.php
proxy_sync.php
recv_1m_client.php
recv_file.php
redis_pool.php
reflection_test.php
ringqueue.php
send_1m_svr.php
sendfile_server.php
serialize.php
serialize2.php
server.c
server.php
server_hot_update_opcache.php
set_cpu_affinity.php
swoole_http_client.php
test.jpg
test_buffer.php
test_server.c
version.php
weather_server.php
include
src
tests
thirdparty
tools
travis
.gitignore
.gitmodules
.travis.yml
CMakeLists.txt
CREDITS
LICENSE
README.md
Version2.md
build.sh
clear.sh
config.m4
make.sh
package.xml
php7_wrapper.h
php_swoole.h
swoole.c
swoole_async.c
swoole_atomic.c
swoole_buffer.c
swoole_channel.c
swoole_channel_coro.cc
swoole_client.c
swoole_client_coro.c
swoole_config.h
swoole_coroutine.cc
swoole_coroutine.h
swoole_coroutine_util.c
swoole_event.c
swoole_http.h
swoole_http_client.c
swoole_http_client.h
swoole_http_client_coro.c
swoole_http_server.c
swoole_http_v2_client.c
swoole_http_v2_client.h
swoole_http_v2_client_coro.c
swoole_http_v2_server.c
swoole_lock.c
swoole_memory_pool.c
swoole_mmap.c
swoole_msgqueue.c
swoole_mysql.c
swoole_mysql.h
swoole_mysql_coro.c
swoole_postgresql_coro.c
swoole_postgresql_coro.h
swoole_process.c
swoole_process_pool.c
swoole_redis.c
swoole_redis_coro.c
swoole_redis_server.c
swoole_ringqueue.c
swoole_runtime.cc
swoole_serialize.c
swoole_serialize.h
swoole_server.c
swoole_server_port.c
swoole_socket_coro.c
swoole_table.c
swoole_timer.c
swoole_trace.c
swoole_websocket_server.c
wechat
.htaccess
autoload.php
wxtmp
.gitignore
.htaccess
.user.ini
404.html
H5B854518.wgt
admin.php
app-release.apk
app_download.html
cash.lock
demo.php
get_startup.php
get_version.php
get_version_new.php
hyhproject.tar.gz
index.html
index.php
reg.lock
robots.txt
146 lines
3.6 KiB
PHP
Executable File
146 lines
3.6 KiB
PHP
Executable File
<?php
|
|
$serv = new swoole_server("127.0.0.1", 9501);
|
|
$serv->set(array(
|
|
'worker_num' => 2,
|
|
//'open_eof_check' => true,
|
|
//'package_eof' => "\r\n",
|
|
'task_worker_num' => 2,
|
|
//'dispatch_mode' => 2,
|
|
//'daemonize' => 1,
|
|
//'heartbeat_idle_time' => 5,
|
|
//'heartbeat_check_interval' => 5,
|
|
));
|
|
function my_onStart($serv)
|
|
{
|
|
echo "MasterPid={$serv->master_pid}|Manager_pid={$serv->manager_pid}\n";
|
|
echo "Server: start.Swoole version is [".SWOOLE_VERSION."]\n";
|
|
//$serv->addtimer(1000);
|
|
}
|
|
|
|
function my_onShutdown($serv)
|
|
{
|
|
echo "Server: onShutdown\n";
|
|
}
|
|
|
|
function my_onTimer($serv, $interval)
|
|
{
|
|
echo "Server:Timer Call.Interval=$interval\n";
|
|
}
|
|
|
|
function my_onClose($serv, $fd, $from_id)
|
|
{
|
|
//echo "Client: fd=$fd is closed.\n";
|
|
}
|
|
|
|
function my_onConnect($serv, $fd, $from_id)
|
|
{
|
|
//throw new Exception("hello world");
|
|
// echo "Client:Connect.\n";
|
|
}
|
|
|
|
|
|
$class = null;
|
|
function my_onWorkerStart($serv, $worker_id)
|
|
{
|
|
global $argv;
|
|
global $class;
|
|
opcache_reset();
|
|
include "hot_update_class.php";
|
|
$class = new HotUpdate();
|
|
if($worker_id >= $serv->setting['worker_num']) {
|
|
swoole_set_process_name("php {$argv[0]} task worker");
|
|
} else {
|
|
swoole_set_process_name("php {$argv[0]} event worker");
|
|
}
|
|
//echo "WorkerStart|MasterPid={$serv->master_pid}|Manager_pid={$serv->manager_pid}|WorkerId=$worker_id\n";
|
|
//$serv->addtimer(500); //500ms
|
|
}
|
|
|
|
function my_onWorkerStop($serv, $worker_id)
|
|
{
|
|
echo "WorkerStop[$worker_id]|pid=".posix_getpid().".\n";
|
|
}
|
|
|
|
function my_onReceive(swoole_server $serv, $fd, $from_id, $data)
|
|
{
|
|
$cmd = trim($data);
|
|
if($cmd == "reload")
|
|
{
|
|
$serv->reload($serv);
|
|
}
|
|
elseif($cmd == "task")
|
|
{
|
|
$task_id = $serv->task("hello world", 0);
|
|
echo "Dispath AsyncTask: id=$task_id\n";
|
|
}
|
|
elseif($cmd == "info")
|
|
{
|
|
$info = $serv->connection_info($fd);
|
|
$serv->send($fd, 'Info: '.var_export($info, true).PHP_EOL);
|
|
}
|
|
elseif($cmd == "broadcast")
|
|
{
|
|
$start_fd = 0;
|
|
while(true)
|
|
{
|
|
$conn_list = $serv->connection_list($start_fd, 10);
|
|
if($conn_list === false)
|
|
{
|
|
break;
|
|
}
|
|
$start_fd = end($conn_list);
|
|
foreach($conn_list as $conn)
|
|
{
|
|
if($conn === $fd) continue;
|
|
$serv->send($conn, "hello from $fd\n");
|
|
}
|
|
}
|
|
}
|
|
//这里故意调用一个不存在的函数
|
|
elseif($cmd == "error")
|
|
{
|
|
hello_no_exists();
|
|
}
|
|
elseif($cmd == "shutdown")
|
|
{
|
|
$serv->shutdown();
|
|
}
|
|
else
|
|
{
|
|
global $class;
|
|
$data .= $class->getData();
|
|
$serv->send($fd, 'Swoole: '.$data, $from_id);
|
|
//$serv->close($fd);
|
|
}
|
|
//echo "Client:Data. fd=$fd|from_id=$from_id|data=$data";
|
|
//$serv->deltimer(800);
|
|
//swoole_server_send($serv, $other_fd, "Server: $data", $other_from_id);
|
|
}
|
|
|
|
function my_onTask(swoole_server $serv, $task_id, $from_id, $data)
|
|
{
|
|
echo "AsyncTask[PID=".posix_getpid()."]: task_id=$task_id.".PHP_EOL;
|
|
$serv->finish("OK");
|
|
}
|
|
|
|
function my_onFinish(swoole_server $serv, $data)
|
|
{
|
|
echo "AsyncTask Finish:Connect.PID=".posix_getpid().PHP_EOL;
|
|
}
|
|
|
|
$serv->on('Start', 'my_onStart');
|
|
$serv->on('Connect', 'my_onConnect');
|
|
$serv->on('Receive', 'my_onReceive');
|
|
$serv->on('Close', 'my_onClose');
|
|
$serv->on('Shutdown', 'my_onShutdown');
|
|
$serv->on('Timer', 'my_onTimer');
|
|
$serv->on('WorkerStart', 'my_onWorkerStart');
|
|
$serv->on('WorkerStop', 'my_onWorkerStop');
|
|
$serv->on('Task', 'my_onTask');
|
|
$serv->on('Finish', 'my_onFinish');
|
|
$serv->on('WorkerError', function($serv, $worker_id, $worker_pid, $exit_code) {
|
|
echo "worker abnormal exit. WorkerId=$worker_id|Pid=$worker_pid|ExitCode=$exit_code\n";
|
|
});
|
|
$serv->start();
|
|
|