My requirement is to query the database at intervals, and then push the code to everyone like the following: while (true) {code ...}} if I use swoolewebsocket's on (& #039; message & #039;) to write this code, I need to open this code for every client connection. How can I query the database at intervals and then push it to everyone?
The code is similar to the following:
While (true ){
$sql ="select 1+1";$count=$mysql->query($sql);foreach($serv->connections as $fd){ $serv->push($fd, $count);}sleep(1000);
}
If I use swoole websocket's on ('message') to write this code, it is required for every client to connect to it.
How can we run a code that all customers can accept ..
Reply content:
My requirement is to query the database at intervals and then push it to everyone.
The code is similar to the following:
While (true ){
$sql ="select 1+1";$count=$mysql->query($sql);foreach($serv->connections as $fd){ $serv->push($fd, $count);}sleep(1000);
}
If I use swoole websocket's on ('message') to write this code, it is required for every client to connect to it.
How can we run a code that all customers can accept ..
Do I remember a timer? But I don't understand either.
If only the message is used, there are two types of messages: one is the message sent by the administrator, the other is sent to other users, and the database is queried every time an administrator message is received, then send the group to others.
If it takes too much time, you can put the main task into the task, so that the administrator can process other messages immediately after sending a message, and the complicated tasks are handed over to the task.