PHP-PUSH technology realizes refresh function
Troyoo.com Beyond Release Date: 2004-08-09 15:01 Publisher: chengxin119 〖Close window〗
Author information: lguser
LGUSER@163.net)
Article Information: Primary Atmosphere Date: 2003 02 Keywords: PHP-PUSH Refresh
Source link:
http://www.troyoo.com
Summary:
After using the server PUSH server, after the client makes a request, establish a permanent connection with the client, and then the server will continue to push the packet to the server according to the request of the client. Those delays that you don't feel will make you feel that the server's response and your request have reached the level of synchronization.
Server Push has been very hot "push" technology, but most of the online CGI information, occasionally seeing such a introduction on a French website, but unfortunately, unclear, only from his procedure I understand something, now I will sort out an example, everyone will learn. Can be used in the data transfer of the chat room, news updates on the website, and so on all types of updated frequently. Before doing refresh mainly through the page.
Or use JavaScript Timeout Reload, but this refresh method depends on the time setting, the continuous data transmission is not determined. After using the server PUSH server, after the client makes a request, establish a permanent connection with the client, and then the server will continue to push the packet to the server according to the request of the client. Those delays that you don't think 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. 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, directly output, IE does not support, I didn't try it out.
Header ("Cache-Control: no-cache);
Header ("prgma: 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, see the MIME type description
/ / 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);
WHILE (1);
}
?>
This is a permanent page (in the case of network constant), constantly outputting the contents of the image, below is the page called. , then open your Netscape or other non-IE browser to view the call page, it seems that there is nothing to change, don't worry, then how to change the 1.jpg, write another PHP page Test, such as getting 2 pictures over time to override 1.jpg (this method you think yourself, override it with copy, as long as 1.jpg has changed). At this time, you will see the image of the call page is automatically updated. You will find a problem in use: how the picture is not automatically updated. This is because the client does not have a request to the server for a while, that is, there is no new content to the browser in a certain period of time, and the connection timeout may occur. What is the solution? You can send an empty signal to the browser in the execution page, similar to the FTP connection, add a print ("") in Do ... while (1); after reading this example, you should know how to deal with Constantly updated, the key in the img.php page (can be checking new content and output), you can have IMG, Script, Frame, etc. when calling. For details, please see: http://www.npds.org/