How does PHP read data every few seconds

Source: Internet
Author: User
Tags php server
How PHP reads data every few seconds
The main function of the project is to write a well-registered COM
Connect and read data to a remote server via PHP calling COM interface
and display the data to the function of the webpage.
$com->connect (server);
$com->read ();

PHP files are now available for reading at regular intervals via Window.setinterval and Ajax calls
However, there is a serious problem with this approach, and each time you read the Connect server
I do not know if there is any way to connect only once and then only need to read.

It is also not useful to try using singleton mode before.

------to solve the idea----------------------
At the end of each request, the current PHP execution process is automatically freed, so PHP has no way.

For the network connection, if your server is Nginx, you can use Nginx to make an HTTP long connection, PHP every time is connected to the local nginx, so that the PHP server connected to the current machine, there is only one network connection.
------to solve the idea----------------------
There is no way to solve this.
The connection will be disconnected after each execution. Unless you're using a socket to connect.
------to solve the idea----------------------
You use the front end is setinterval, can not do connect once, and then read directly

You can change to the front websocket and PHP sockets

------to solve the idea----------------------
Or you don't understand what I mean: As long as your program does not terminate, you do not need to reconnect
However, in an HTTP session, the PHP program only runs during the session, that is, the session ends and the program terminates
So reconnecting is inevitable. Also do not mistakenly understand the C language program behavior, because before the program closes, he has been running. So there's no need to reconnect.
If you use WebSocket, then the session is not HTTP, but the WebSocket protocol (WS) is not the same as the natural expression.
  • Related Article

    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.