walkor / gatewayworker Goto Github PK
View Code? Open in Web Editor NEWDistributed realtime messaging framework based on workerman.
License: MIT License
Distributed realtime messaging framework based on workerman.
License: MIT License
What is process_timeout? and why occurred?
2017-05-13 21:13:26 pid:23206 process_timeout:
#1 /home/app/vendor/workerman/workerman/Events/React/StreamSelectLoop.php(149): pcntl_signal_dispatch()
#2 /home/app/vendor/react/event-loop/src/StreamSelectLoop.php(225): Workerman\Events\React\StreamSelectLoop->streamSelect(Array, Array, 10000)
#3 /home/app/vendor/react/event-loop/src/StreamSelectLoop.php(205): React\EventLoop\StreamSelectLoop->waitForStreamActivity(10000)
#4 /home/app/vendor/workerman/workerman/Events/React/StreamSelectLoop.php(104): React\EventLoop\StreamSelectLoop->run()
#5 /home/app/vendor/workerman/workerman/Worker.php(1561): Workerman\Events\React\StreamSelectLoop->loop()
#6 /home/app/vendor/workerman/gateway-worker/src/BusinessWorker.php(183): Workerman\Worker->run()
#7 /home/app/vendor/workerman/workerman/Worker.php(959): GatewayWorker\BusinessWorker->run()
#8 /home/app/vendor/workerman/workerman/Worker.php(922): Workerman\Worker::forkOneWorker(Object(GatewayWorker\BusinessWorker))
#9 /home/app/vendor/workerman/workerman/Worker.php(430): Workerman\Worker::forkWorkers()
#10 /home/index.php(45): Workerman\Worker::runAll()
#11 {main}
I found if the data size is large, sendToGroup()
will split the string then send next time.
How to know and set packet size limit?
$task = new Worker();
$task->name = 'YourAppTestTimer';
$task->count = 1;
$task->onWorkerStart = function($task)
{
$time_interval = 2.5;
Timer::add($time_interval, "timerProcess",array(),true);
};
function timerProcess(){
$t = ORM::for_table("test")->find_one(1);
$t->end_time = Carbon::now()->toDateTimeString();
$t->save();
echo "task run\n";
}
Worker::runAll();
use "php start.php start" it will execute timerProcess every 2.5 seconds.
But use "php start.php start -d" , it won't exceute timerProcess function.why?
@walkor In distributed deployment I see the following error when I start new gateways in a new machine
stream_socket_client(): unable to connect to tcp://10.10.10.50:2320 (Connection timed out)
/vendor/workerman/gateway-worker/src/Lib/Gateway.php:363
10.10.10.50:2320
is a gateway in another machine and the load is very low
When I start new gateway in new machine , all business workers in all machines hangs for 10-15 seconds
I think we have stream_socket_client
in business worker too and it's in synchronous mode
分布式是基于SESSION的?基于SESSION的能支持分布式?好像不行吧,分组的数据都是通过SESSION,而我们知道SESSION默认情况下是不支持集群,跟机器走的一组数据,这是我想问的地方。
Is there a server stop callback function in GatewayWorker?
because I want to record server shut down time,
when restart server, use the shut down time to recalculate the end time of my gameplay event.
Another question,If operating system or web server(nginx) restart,
how can I know the server previous shut down time?
是在直播间进出房间的场景,用户进入直播间A,我在当前用户的session里记录A $_SESSION['rooms']['A']=1,用户退出A时,我把A从session里unset掉 unset($_SESSION['rooms']['A'])。现在是网页里用过websocket建立连接,用户关闭页面时用户退出A,随即网页关闭,websocket连接断开了。
问题:我会在后端socket断开连接的回调里检测用户是否还有未关闭的房间,有的话会把用户退出房间,可能是 退出房间和socket连接间隔太短了,退出房间时session更新了,但回调时这时session里的A并没清除,从而导致用户会再退出A一次。
Workerman version:3.3.2
GatewayWorker master分支
PHP version:5.6.2
CentOS 7
[ 2017-08-24T14:07:50+08:00 ][ error ] [2]file_get_contents(/var/www/game/vendor/workerman/workerman/../_var_www_game_worker_start.php.pid): failed to open stream: No such file or directory
[ 2017-08-24T14:07:57+08:00 ][ error ] [2]stream_select(): unable to select [4]: Interrupted system call (max_fd=9)
[ 2017-08-24T14:07:57+08:00 ][ error ] [2]stream_select(): unable to select [4]: Interrupted system call (max_fd=9)
[ 2017-08-24T14:07:57+08:00 ][ error ] [2]stream_select(): unable to select [4]: Interrupted system call (max_fd=11)
[ 2017-08-24T14:12:21+08:00 ][ error ] [2]stream_select(): unable to select [4]: Interrupted system call (max_fd=12)
[ 2017-08-24T14:12:21+08:00 ][ error ] [2]stream_select(): unable to select [4]: Interrupted system call (max_fd=9)
[ 2017-08-24T14:12:21+08:00 ][ error ] [2]stream_select(): unable to select [4]: Interrupted system call (max_fd=9)
[ 2017-08-24T14:22:38+08:00 ][ error ] [2]stream_select(): unable to select [4]: Interrupted system call (max_fd=12)
[ 2017-08-24T14:22:38+08:00 ][ error ] [2]stream_select(): unable to select [4]: Interrupted system call (max_fd=9)
[ 2017-08-24T14:22:38+08:00 ][ error ] [2]stream_select(): unable to select [4]: Interrupted system call (max_fd=9)
业务逻辑可以用mockery
之类模拟行为测试,那其他部分比如生命周期之类的,该怎么测试呢,能否提供一些建议或者示例呢
1- What is the memory
showing in the php index.php status
, current using memory? Peak memory?
2- How Gateway (G) , Business worker (B) and Register (R) is connected together?
If we have 1 R , 10 G and 20 B , how are connected? and how many connection have R , B and G?
3- If I have a GatewayClient in my BusinessWorker and I use sendToClient
OR sendToUid
, What happens exactly? If I have 10 Gateway , I think for both command each 10 gateway receive a message
Hi
According to the following codes
https://github.com/walkor/GatewayWorker/blob/master/src/Gateway.php#L409-L414
each client is indirectly connected to specific business worker
From another business worker I want to send a command to the specific business worker using clientId
In other words , If I have business worker A (BWA) and B (BWB) and clientId
= X is connected to BWA , Some times I need from BWB send a command to BWA that do something
How is possible ?
测试机:mac10.14.1
php环境:7.3.2
框架版本:thinkphp5.1
gatewayworker版本:"workerman/gateway-worker": "^3.0"
错误:使用th5的orm或连接导致worker进程退出;worker[MedicalBoxWorker:920] exit with status 11
补充:
(1)此错误Exception无法捕获;
(2)在php7.1环境没有问题;
(3)Worker::runAll()启动前可用使用DB,Events中的回调(onWorkerStart,onConnect,onMessage)无法使用
I have too many Gateway: Worker->name conflict.
error in log
Why?
冒昧的请教下:在使用GatewayWorker的时候(websocket),在events.php文件onMessage函数里面使用sendToAll能推送给客户端成功接收,但是使用sendToUid和sendToClient给指定客户端推送消息,可能是什么原因呢?
与CMD_UPDATE_SESSION相配套, 建议增加一个CMD_GET_SESSION命令获取任一用户(而不是当前用户)的session,
或者说是提供一个getClientInfo()函数
Hi, worker,
according to the example in workman, I used it in gateway, but it doesn't work, the client could not receive the message!
$asyncMysql->query('select * from user', function ($command, $mysql) {
if ($command->hasError()) {
$error = $command->getError();
} else {
$results = $command->resultRows;
$fields = $command->resultFields;
\GatewayWorker\Lib\Gateway::sendToCurrentClient(json_encode($results));
}
});
I also use sendToUid replace to sendToCurrentClient ..... same problem
Do I need use $connections as workerman example? If so, how can i get $connect in gateway
1.用status命令查看,有很多65280的错误。这种错误日志在什么地方? 还是需要自己代码里面做处理?
2.默认的项目里面也没有生成workerman.log日志,是需要设置什么?
麻烦帮忙答疑,谢谢!
Hi Walkor
I am trying to set some custom headers when replying to client from inside Events.php run from businessWorker and can't figure out how to do it.
http server is started in the gateway.php with:
// gateway FwUpdHttpGateway process
$FwUpdHttpGateway = new Gateway("http://0.0.0.0:9090");
In Events.php
public static function onMessage($client_id, $message){
# Use Workerman\Protocols\Http::header to send header to clients.
# walkor/workerman#151
Http::header("Content-type: text/plain");
Http::header("Accept-Ranges: bytes");
Http::header("Content-Disposition: attachment; filename=test");
$fw_update_data = array(
"version" => $fwupd_name,
"firmware" => "?".$fwupd_name
);
$fw_update_data = json_encode($fw_update_data);
#Send data to client
Gateway::sendToClient($_SERVER['GATEWAY_CLIENT_ID'], $fw_update_data);
}
Thankx
Hello
Swoole is an Event-driven asynchronous & concurrent & coroutine networking engine with high performance for PHP.
Here is Github repository https://github.com/swoole/swoole-src
There is some advantage over workerman , So I want to replace GatewayWorker with swoole but I want to connect swoole to register and business worker , How is possible?
I want to keep all GatewayWorker features like Distributed deployment
Best Regards
@walkor if we have many powerful machines
How many gateway and business worker can exist in workerman system ??
If we choose libevent
or event
as main event loop
I already record Timer id in the memcached.
So I can get TimerID from memcached.
but How can I delete Timer when code is not in Event.php?
If I call Timer::del($timerIDFromMemcache), I think it's not working,
because the Timer doesn't initialize.
I want to know how clientId
is generated?
Is it unique in multiple server ( Distributed Deployment )? that means If we have 3 server and I have clientId A
in server 1 , is it possible some one or me have A
as client id in server 2 or 3 ?
Is it unique in time , that means If my clientId is B
and I close connection is it possible later some one or me have B
as client id?
I have 8 machine and run in each machine 10 gateway and 10 business worker
I have heavy loads , and have a bad problem
In each machine CPU usage of all gateways is same , when in a single machine , CPU usage of gateways reaches 100% Whole system (All users in all servers) hangs and not works , even when other machines CPU usage of gateways and business worker is 10-30%
Currently I'm using stream_select
, I think when a business worker send message to gatway with 100% CPU usage , The PHP locked on the line and with timeout skip from the line ? Right? or not?
Where is problem? How to solve?
超出最大值后,REDIS中GLOBAL_CLIENT_ID_KEY 的值为“i:0;"
log记录为
createGlobalClientId fail GatewayWorker\Lib\StoreDriver\Redis ERR not an integar or out of range.
redis版本号为
Redis server v=3.0.3 sha=00000000:0 malloc=jemalloc-3.6.0 bits=64 build=e2c78c7971ad5d9e
@walkor 我想应用您写的GatewayWorker,我在laravel console 分别创建了StartRegister.php、StartBusinessworker.php、StartGateway.php 我在浏览器console请求websocket是成功的,请问在laravel 框架里我改怎么接受 websocket 数据呢?
I open three GatewayWorker Servers in an operating system.
I have the same code in three different folder ,and the folder structure is below:
Peter or Leon or Test folder
-GatewayWorker
--Applications
--- YourApp
---- Config
----- Config.php (add by myslef)
------ Db.php
------ Store.php
...(Skip)
this is Test's Config.php code blow:
$port = 8282;
$logFileNamePostfix = "";
this is Peter's Config.php code blow:
$port = 8283;
$logFileNamePostfix = "Peter";
this is Leon's Config.php code blow:
$port = 8284;
$logFileNamePostfix = "Leon";
the $port will apply for "$gateway = new Gateway("Text://0.0.0.0:".$port);"
the $logFileNamePostfix will apply for
"Worker::$stdoutFile = '/var/log/TTT_SocketServer_'.$logFileNamePostfix.Carbon::now()->toDateString().'.log';" in start_bussinessworker.php
So I execute "php start.php start -d" in three different folder, I get three server using different port.
and output server log into three different file.
I found that three Log file doesn't often show new log,sometimes it show log,but sometimes it dosen't.
why?
例如
`
$coket = ‘text://0.0.0.0:3238’;
new Register($coket);
$gateway = new Gateway("ws://0.0.0.0:8070");
$gateway->registerAddress = $socket;
`
报错信息
Warning: stream_socket_client(): php_network_getaddresses: getaddrinfo failed: Name or service not known in
不同协议间心跳设置是相通的,能否加以区分?
看到最近的更新修复了上一个版本中createGlobalClientId failed
这个问题,commit message里没有提到,觉得还是提示下同样遇到这个问题的童鞋,以便交流:
2.0.5之前的createGlobalClientId()
依赖Redis/Memcached生成client_id(global_client_id
),createGlobalClientId()函数里没有处理Redis/Memcached异常,而直接将返回值作为key保存客户端信息。可能导致后续Redis恢复,部分连接无法正常更新Redis中数据,需要重启Workman。
2.0.5里generateConnectionId()
使用变量_connectionIdRecorder
生成client_id,不依赖Redis,建议大家使用这个修改。
The url is : http://doc2.workerman.net/get-all-group-id-list.html
In the first line
Gateway::getAllUidList
Should be
Gateway::getAllGroupIdList
Hola! @dandanlee has created a ZenHub account for the walkor organization. ZenHub is the only project management tool integrated natively in GitHub – created specifically for fast-moving, software-driven teams.
To get set up with ZenHub, all you have to do is download the browser extension and log in with your GitHub account. Once you do, you’ll get access to ZenHub’s complete feature-set immediately.
ZenHub adds a series of enhancements directly inside the GitHub UI:
Still curious? See more ZenHub features or read user reviews. This issue was written by your friendly ZenHub bot, posted by request from @dandanlee.
Which is newer?
https://github.com/walkor/GatewayClient/blob/master/Gateway.php
OR
https://github.com/walkor/GatewayWorker/blob/master/src/Lib/Gateway.php
And I think it is better to add GatewayClient
as a dependency of GatewayWorker
using composer
PHP Fatal error: Class '' not found in D:\wwwroot\GatewayWorker-for-win\vendor
workerman\workerman-for-win\Connection\TcpConnection.php on line 310
I create inbound rule Custom TCP rule port 10001 in aws
I create socket server connection by Php GatewayWorker, the port is 10001.
telnet public ip result is No route to host, how to fix it?
[centos@ip-private ip ~]$ telnet [private ip] 10001
Trying [private ip]...
Connected to [private ip].
Escape character is '^]'.
[centos@ip-private ip ~]$ telnet [public ip] 10001
Trying [public ip]...
telnet: connect to address [public ip]: No route to host
[centos@ip-private ip ~]$ telnet [public ip] 80
Trying [public ip] ...
Connected to [public ip] .
Escape character is '^]'.
Hello Walkor,
Very nice work you did with the Worker project.
While looking at documentation for GatewayWorker I found out on React/stomp page that
Note: This item has expired and cannot be used. Do not install
Is this true? Is there a versioning mismatch ?
Can it now be used?
Thank you.
How to transmit video or pictures while chatting,The way through the flow
聊天时如何传输视频或图片,以流的方式
In the following line
https://github.com/walkor/GatewayWorker/blob/master/src/Lib/Gateway.php#L774
you use stream_select
, it is better to use event loops
Can I ask what is $client_array
? is it all connected users for example all web socket connections? or it is just Gateway->BusinessWorker connections?
Hi
What happens if I do this , I deployment distribution , I set different name for gateways , for example in server 1 I set the name of gateway as GS1
and in server 1 I set GS2
, is there any issue if I do this?
$ php start.php start -d
$ php start.php status <<<< I can see the server status information
But second day, I can't see anything about status,why?
[centos@ip-172-31-13-63 GatewayWorker]$ php start.php status
PHP Warning: Module 'mcrypt' already loaded in Unknown on line 0
PHP Warning: Module 'msgpack' already loaded in Unknown on line 0
Workerman[start.php] status
Event回调,onWebSocketConnect, onConnect ,onMessage在并发场景中的bug
bug场景:
onWebSocketConnect 或者是 onConnect 对首次接入 做拒绝处理,或授权验证 (处理结果如:
Gateway::closeCurrentClient ,或者直接exit)。
但是在压测高并发场景下 ,仍然会穿透给 onMessage ,也就是说, 如果想攻击你 ,拿着消息体 连接 gateway 即可。(如 拿着发送消息的json结构,不断攻击连接端口,则会造成穿透至 onMessage )
windows服务器上,使用了2000端口,防火墙也开了入站规则,还是连接不上
个人愚见,把GatewayWorker核心和workerman的核心用composer来加载。这个项目就当是一个官方实例。^_^
命令
git clone https://github.com/walkor/workerman-chat
cd workerman-chat/
composer install
php start.php start
** 版本**
Loading composer repositories with package information
Updating dependencies (including require-dev)
出现下面的情况
Press Ctrl+C to stop. Start success.
worker[ChatGateway:76065] exit with status 11
worker[ChatGateway:76064] exit with status 11
worker[ChatGateway:76063] exit with status 11
worker[ChatBusinessWorker:76062] exit with status 11
worker[ChatGateway:76066] exit with status 11
worker[ChatBusinessWorker:76061] exit with status 11
worker[ChatBusinessWorker:76060] exit with status 11
worker[ChatBusinessWorker:76059] exit with status 11
worker[ChatGateway:76072] exit with status 11
worker[ChatGateway:76071] exit with status 11
worker[ChatGateway:76073] exit with status 11
worker[ChatGateway:76075] exit with status 11
worker[ChatBusinessWorker:76074] exit with status 11
worker[ChatBusinessWorker:76076] exit with status 11
worker[ChatBusinessWorker:76078] exit with status 11
worker[ChatGateway:76079] exit with status 11
worker[ChatGateway:76080] exit with status 11
worker[ChatGateway:76082] exit with status 11
worker[ChatGateway:76081] exit with status 11
worker[ChatBusinessWorker:76083] exit with status 11
worker[ChatGateway:76086] exit with status 11
worker[ChatGateway:76087] exit with status 11
worker[ChatBusinessWorker:76085] exit with status 11
worker[ChatGateway:76088] exit with status 11
worker[ChatGateway:76089] exit with status 11
worker[ChatBusinessWorker:76084] exit with status 11
worker[ChatGateway:76092] exit with status 11
worker[ChatGateway:76091] exit with status 11
worker[ChatGateway:76094] exit with status 11
worker[ChatGateway:76095] exit with status 11
....
如题
gatewaywork集群下有多台gateway服务器,客户端(PC、APP)应该连接哪一个gateway?
比如:
1,192.168.1.1机器的start_gateway.php配置$gateway = new Gateway("Websocket://192.168.1.1:7272");
2,192.168.1.2机器的start_gateway.php配置$gateway = new Gateway("Websocket://192.168.1.2:7272");
这时候客户端应该如何做,还是随机的连接这两个gateway任意一个?
GatewayWorker 优雅退出是会被卡在的,而workerman却是可以的
GatewayClient::closeClient is not working in Distributed Deployment
I cannot close a client connect to server #2 from server #1
Also Please implement closeUid
walkor/GatewayClient#2
Best regards
client1需要和client2通信,client1连接到gateway1, gateway1把client1的信息转发给businessworker1, client2连接到的gateway2, 此时,businessworker1怎么把消息转发到gateway2上的?因为gateway1并没有client1的连接。谢谢~
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.