How does swoole implement a single query and then send it to everyone

WBOY
Release: 2016-08-18 09:16:20
Original
1260 people have browsed it

My requirement is to query the database every once in a while and then push it to everyone
The code is similar to the following:
while(true){

<code>$sql ="select 1+1";
$count=$mysql->query($sql);
foreach($serv->connections as $fd)
{
    $serv->push($fd, $count);
}
sleep(1000);</code>
Copy after login
Copy after login

}
If I now use swoole websocket's on('message') to write this, it will open a copy of this code and run it every time the client connects.
How can we run a code so that all customers can receive it? .

Reply content:

My requirement is to query the database every once in a while and then push it to everyone
The code is similar to the following:
while(true){

<code>$sql ="select 1+1";
$count=$mysql->query($sql);
foreach($serv->connections as $fd)
{
    $serv->push($fd, $count);
}
sleep(1000);</code>
Copy after login
Copy after login

}
If I use swoole websocket's on('message') to write this, it will open a copy of this code and run it every time the client connects.
How can we run a code so that all customers can receive it? .

I remember there is a timer, right? But I don’t understand either

If you only use messages, divide the messages into two types, one is the message sent by the administrator, and the other is sent to other users. Then every time you receive a message from an administrator, check the database once, and then send it to other users in bulk. people.
If you think this will take up too much time, you can put the main tasks in tasks, so that the administrator can return immediately after sending a message to process other messages, and leave complex things to tasks.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!