PHP-Push to achieve refresh

Source: Internet
Author: User
Serverpush was a very popular "push" technique some time ago. However, most of the materials on the Internet are cgi materials. I accidentally saw such a preference on a French website, but I am sorry that I cannot understand the French language, I can only understand something from his program. now I am packing up an example of the "push" technique that was very popular some time before Server push. However, most of the materials on the Internet are cgi, I accidentally saw such a preference on a French website. sorry, I don't understand French. I can only read something from his program. now I will give you some examples to learn. It can be used for data transmission in chat rooms, message updates on websites, and various frequently updated pages.

Previously, it was important to add tags on the page.

& Lt; META HTTP-EQUIV = refresh content = 'time; URL = url' & gt;

Or the timeout reload of javascript is applied. However, the refresh method depends on the time settings. data cannot be transmitted continuously and the time is difficult to determine. The Server that uses Server push establishes a permanent connection with the client after the client makes a request. then, the Server will push data packets to the Server according to the client's request. The latency you don't notice will make you feel that the server's response and your request have reached the level of synchronization.

Let's take a look at the example and explain it again.

Img. php

<? Php
Set_time_limit (0 );
$ File = './1.jpg ';
$ Sep = 'girlskickassitsayssoonatshirt ';
If (ereg ('. * MSIE. *', $ HTTP_SERVER_VARS ['http _ USER_AGENT ']) {
// If it is an IE browser, the system exits after direct output, and IE does not support it. I have never tried it.
Header ('cache-Control: no-cache ');
Header ('pragma: no-cache ');
Header ('content-type: image/jpeg ');
Header ('content-size: '. filesize ($ file ));
Readfile ($ file );
} Else {
Header ('content-Type: multipart/x-mixed-replace; boundary = $ sep ');
// Here is the key. let's take a look at the MIME type clarification.

// You will understand
Print '-- $ sep
';
Do {
Print 'Content-Type: image/jpeg
';
Readfile ($ file );
Print'
-- $ Sep
';
Flush ();
$ Mt = filemtime ($ file );
Do {
Sleep (1 );
Clearstatcache ();
} While ($ mt = filemtime ($ file ));
} While (1 );
}
? >

This is a permanent page (network constantly) that constantly outputs image content. The following is the called page ., Renewal has been changed ). Then you can see that the image on the called page is automatically updated.

In the app, you will invent a Title: how can images not be automatically updated. This is because the client does not make a request to the server within a period of time, that is, there is no new content to input to the browser within a period of time, and connection timeout may occur. What measures should be taken to solve the problem? You can add an empty signal to the browser on the fulfillment page, similar to the ftp connection method. print ('') is added between do... while (1) on the above page ('');

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.