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

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.