Home Backend Development PHP Tutorial Minimize data transfer - store data on the client_PHP tutorial

Minimize data transfer - store data on the client_PHP tutorial

Jul 21, 2016 pm 04:07 PM
for exist storage client Will data data transmission yes minimize program programmer language output

Outputting programs into other languages ​​is one of the things programmers love. On the WEB we have
two different programming environments: the client (browser) and the server side. According to the definition of the HTTP protocol,
we You can write server-side programs that output other languages ​​on the client. We chose server-side language and javascript as the client-side output. In this question we will demonstrate to you how to use
this solution to store data on the client, and reach the server and client in applications such as chat rooms, news systems or other applications you want to
implement ( browser) minimal data transfer.

Requires the following support:
PHP4
JavaScript
Frames

Main idea:

We have been trying to develop a chat room based on HTTP protocol using PHP (HTTP CHAT ROOM),
Although the HTTP protocol is not a good protocol for chat, it can not be affected by firewalls or proxies.
PHP can completely implement this function without using JAVA APPLETS, for chat rooms There are two main problems:
First, because IE does not support SERVER PUSH technology, so we can only use CLIENT PULL technology (that is,
the client automatically refreshes). The second problem is deeper: because the The idea is to refresh on the client, so the server must transmit all messages each time, which means a large amount of data transmission. This is also the main reason for chat room delay. This article attempts to solve this problem. :
Using frame technology (frames) you can refresh specified pages without having to reload other pages, which can
reduce the amount of service/client (C/S) data transmission. Our model is based on this scheme.
"master" file: define the framework structure
"loader" page: import data
"display" page: display data
In this scheme, the "loder" box is automatically refreshed every "x" seconds ——Our idea is to store the data in the "master"
file, so that the "loder" page only needs to request data from the server that the client does not have. We use timestamp (timestamp)
to mark Each message determines which messages must be sent to the client and which do not need to be transmitted. We use PHP4.0's session management (session)
to store the client's last updated timestamp (last timestamp) so that the timestamp is visible to both the server and the client. When the "loader" file
receives data from the "master" file (note: the "master" file is large, but it is only transmitted once), it refreshes the display page ("diaplay")
and "display" The page simply calls a javascript function named "displaymsgs()" in the "master" file to display the message. This function dynamically displays
the data stored in the "master" file. The following is the general flow chart:
1. The browser requests the "master" page (frame), the "master" page is transmitted from the server to the client (browser), and then the "master"
file generates the frame, and the "loader" and "display" pages are transferred to client.
2. On the server side, the "loader" file will be analyzed: If the client does not define the "timestamp" session variable, the "loder" file will
get all the data from the server and generate javascript code to store the data in the "master" file. Then save the "timestamp" variable as
session variable.
3. The "loder" page generates javascript code to refresh the "display" page.
4. The refresh request causes the "display" page to call the "diaplaymsgs()" javascript function to display data
5. Go back to step 2 every "x" seconds

We can think of it as follows:
========================= ===============================
"master" file: very large, defines the displaymsgs() function and storage data and initial values.
"loader" file: small, retrieves data from the server and generates javascript code
"display" file: very small, calls the "diaplaymsgs()" function of the "master" file
==== ================================================== ===
Note: The "master" file is only transferred once
"loder" and "display" files are refreshed every "x" seconds
"loder" may be very large the first time it is transferred , but it will be very small in the future
The "diaplay" file will remain unchanged

If you are still not clear about the above ideas, below we will create a chat room to explain the method in detail. This chat room Just for a simple demonstration
so it may not be very useful, but you can definitely use this idea to build more complex chat rooms, remember this idea is not just for chat rooms. :)

First, please use the mysql database form:
============================
create table testeable (
timestamp datetime,
message text
);
=========================== =
The "master" file is as follows:
===================================== ===========
<script> <br> lines=new Array(); <br> function displaymsgs() { <br> for(i=0;i<lines.length ;i++) { <br> display.document.write(lines[i]); <br> display.document.write('<BR>'); <br>                                                                                                 script> <br>  <frameset cols="1" rows="20,60,20" border="0"> 🎜>                                                                                                                                                             ================================================== <br> Note: The "form" file is a speech box that provides users with input speech boxes.<br><br> "display" file content: <br> ===================== <br> <script> <br> top.displaymsgs( );:) <br><br> "loader" file: <br> ==================== <br> <?php <br><br> session_start (); // Use Sessions here! <br><br> if(!isset($timestamp)) { <br> //If "timestamp" is not defined, define it and set it to 0 <br> $timestamp= 0;                                                                                    <br> // Find information that the client does not have <br> $query="select * from testeable where timestamp>'$timestamp'"; <br> $result=mysql_query($query,$dab); <br> $ msgs = array (); <br> <br> // In this cycle, we store the latest news/data, and set "TimestAmp" to the current maximum value <br> <br> While ($ resql_fetch_array ($ Result )) { <br> $msgs[]=$res["message"]; <br> if($res["timestamp"]>$timestamp) { <br> $timestamp=$res["timestamp"] ; <br>                                                                                                                                                                                                                            🎜>                 // here Loop we generate javascript code <br> // Store the latest data obtained from the server into the "master" page (note: use "top" to point to the top window (master) <br><br> for($i= 0;$i<$count($msgs);$i++) { <br>                                                                                             "); ?>"; <br>                                                                                                                                                                  ; <br> top.display.location.reload(); <br> </script>

Refresh every 4 seconds -->
                                                                                                                                                           ====================================

"form" page:
====================
                                                                                            )) {
$timestamp=0;
}  

        // 显示表单,产生"timestamp"变量.  
        if (isset($msg)) {  
                $dab=mysql_connect("localhost","root","seldon");  
                mysql_select_db("testbase",$dab);  
               $query="insert into testeable(timestamp,message) values(now(),'$msg')";  
               mysql_query($query,$dab);  
               // 得到timestamp 后的所有消息
                $query="select * from testeable where timestamp>'$tt'";  
               $result=mysql_query($query,$dab);  
               $msgs=array();$i=0;$timestamp=0;  
                while($res=mysql_fetch_array($result)) {  
                    $msgs[]=$res["message"];  
                    if($res["timestamp"]>$timestamp) {  
                            $tt=$res["timestamp"];  
                    }  
                }  
                session_register("timestamp");  

            ?>  
              <script>  <br>              <?php  <br>                 for($i=0;$i<$count($msgs);$i++) {  <br>            ?>  <br>                top.lines[top.lines.length]="<?print("$msgs[$i]");?>";  <br>            <?php  <br>             }  <br>              ?>  <br>            top.display.location.reload(); //刷新"display"页 <br>              </script>  
            }  
    ?>  
    

" method="post">  
    Message:  
      
    
  
    =====================================================
    注:我们使得在"form"页提交发言时,马上刷新"display"页面,这可以达到对发言人来说马上发言马上
    显示,更体现实时性。

As you can see, this chat room is very simple, this is the Minimum Customer/Service (C/S) data transfer skill, using this technology you can achieve the minimum data transfer, Again, remind you: this technology is not meant for chat rooms!
================================================== ========
The above was tested on win98+apache1.3+php4.03 platform!
If you have any suggestions or questions, please contact Feiyang Community (http://feiyschool.51.net)
Or send an email to feiyhy@sina.com
Please give me your advice, thank you!
================================     
English original author: Luis Argerich, Alejandro Mitrou
English The URL of the original text: http://www.phpbuilder.com

[The copyright of this article is jointly owned by the author and Aosuo.com. If you need to reprint, please indicate the author and source]

http://www.bkjia.com/PHPjc/315052.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/315052.htmlTechArticleExporting programs to other languages ​​is one of the things programmers love. On the WEB we have two different Programming environment: client (browser) and server side, according to the definition of HTTP protocol,...
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to make Google Maps the default map in iPhone How to make Google Maps the default map in iPhone Apr 17, 2024 pm 07:34 PM

The default map on the iPhone is Maps, Apple's proprietary geolocation provider. Although the map is getting better, it doesn't work well outside the United States. It has nothing to offer compared to Google Maps. In this article, we discuss the feasible steps to use Google Maps to become the default map on your iPhone. How to Make Google Maps the Default Map in iPhone Setting Google Maps as the default map app on your phone is easier than you think. Follow the steps below – Prerequisite steps – You must have Gmail installed on your phone. Step 1 – Open the AppStore. Step 2 – Search for “Gmail”. Step 3 – Click next to Gmail app

Open source! Beyond ZoeDepth! DepthFM: Fast and accurate monocular depth estimation! Open source! Beyond ZoeDepth! DepthFM: Fast and accurate monocular depth estimation! Apr 03, 2024 pm 12:04 PM

0.What does this article do? We propose DepthFM: a versatile and fast state-of-the-art generative monocular depth estimation model. In addition to traditional depth estimation tasks, DepthFM also demonstrates state-of-the-art capabilities in downstream tasks such as depth inpainting. DepthFM is efficient and can synthesize depth maps within a few inference steps. Let’s read about this work together ~ 1. Paper information title: DepthFM: FastMonocularDepthEstimationwithFlowMatching Author: MingGui, JohannesS.Fischer, UlrichPrestel, PingchuanMa, Dmytr

Clock app missing in iPhone: How to fix it Clock app missing in iPhone: How to fix it May 03, 2024 pm 09:19 PM

Is the clock app missing from your phone? The date and time will still appear on your iPhone's status bar. However, without the Clock app, you won’t be able to use world clock, stopwatch, alarm clock, and many other features. Therefore, fixing missing clock app should be at the top of your to-do list. These solutions can help you resolve this issue. Fix 1 – Place the Clock App If you mistakenly removed the Clock app from your home screen, you can put the Clock app back in its place. Step 1 – Unlock your iPhone and start swiping to the left until you reach the App Library page. Step 2 – Next, search for “clock” in the search box. Step 3 – When you see “Clock” below in the search results, press and hold it and

Google is ecstatic: JAX performance surpasses Pytorch and TensorFlow! It may become the fastest choice for GPU inference training Google is ecstatic: JAX performance surpasses Pytorch and TensorFlow! It may become the fastest choice for GPU inference training Apr 01, 2024 pm 07:46 PM

The performance of JAX, promoted by Google, has surpassed that of Pytorch and TensorFlow in recent benchmark tests, ranking first in 7 indicators. And the test was not done on the TPU with the best JAX performance. Although among developers, Pytorch is still more popular than Tensorflow. But in the future, perhaps more large models will be trained and run based on the JAX platform. Models Recently, the Keras team benchmarked three backends (TensorFlow, JAX, PyTorch) with the native PyTorch implementation and Keras2 with TensorFlow. First, they select a set of mainstream

Slow Cellular Data Internet Speeds on iPhone: Fixes Slow Cellular Data Internet Speeds on iPhone: Fixes May 03, 2024 pm 09:01 PM

Facing lag, slow mobile data connection on iPhone? Typically, the strength of cellular internet on your phone depends on several factors such as region, cellular network type, roaming type, etc. There are some things you can do to get a faster, more reliable cellular Internet connection. Fix 1 – Force Restart iPhone Sometimes, force restarting your device just resets a lot of things, including the cellular connection. Step 1 – Just press the volume up key once and release. Next, press the Volume Down key and release it again. Step 2 – The next part of the process is to hold the button on the right side. Let the iPhone finish restarting. Enable cellular data and check network speed. Check again Fix 2 – Change data mode While 5G offers better network speeds, it works better when the signal is weaker

The vitality of super intelligence awakens! But with the arrival of self-updating AI, mothers no longer have to worry about data bottlenecks The vitality of super intelligence awakens! But with the arrival of self-updating AI, mothers no longer have to worry about data bottlenecks Apr 29, 2024 pm 06:55 PM

I cry to death. The world is madly building big models. The data on the Internet is not enough. It is not enough at all. The training model looks like "The Hunger Games", and AI researchers around the world are worrying about how to feed these data voracious eaters. This problem is particularly prominent in multi-modal tasks. At a time when nothing could be done, a start-up team from the Department of Renmin University of China used its own new model to become the first in China to make "model-generated data feed itself" a reality. Moreover, it is a two-pronged approach on the understanding side and the generation side. Both sides can generate high-quality, multi-modal new data and provide data feedback to the model itself. What is a model? Awaker 1.0, a large multi-modal model that just appeared on the Zhongguancun Forum. Who is the team? Sophon engine. Founded by Gao Yizhao, a doctoral student at Renmin University’s Hillhouse School of Artificial Intelligence.

The U.S. Air Force showcases its first AI fighter jet with high profile! The minister personally conducted the test drive without interfering during the whole process, and 100,000 lines of code were tested for 21 times. The U.S. Air Force showcases its first AI fighter jet with high profile! The minister personally conducted the test drive without interfering during the whole process, and 100,000 lines of code were tested for 21 times. May 07, 2024 pm 05:00 PM

Recently, the military circle has been overwhelmed by the news: US military fighter jets can now complete fully automatic air combat using AI. Yes, just recently, the US military’s AI fighter jet was made public for the first time and the mystery was unveiled. The full name of this fighter is the Variable Stability Simulator Test Aircraft (VISTA). It was personally flown by the Secretary of the US Air Force to simulate a one-on-one air battle. On May 2, U.S. Air Force Secretary Frank Kendall took off in an X-62AVISTA at Edwards Air Force Base. Note that during the one-hour flight, all flight actions were completed autonomously by AI! Kendall said - "For the past few decades, we have been thinking about the unlimited potential of autonomous air-to-air combat, but it has always seemed out of reach." However now,

Can't allow access to camera and microphone in iPhone Can't allow access to camera and microphone in iPhone Apr 23, 2024 am 11:13 AM

Are you getting "Unable to allow access to camera and microphone" when trying to use the app? Typically, you grant camera and microphone permissions to specific people on a need-to-provide basis. However, if you deny permission, the camera and microphone will not work and will display this error message instead. Solving this problem is very basic and you can do it in a minute or two. Fix 1 – Provide Camera, Microphone Permissions You can provide the necessary camera and microphone permissions directly in settings. Step 1 – Go to the Settings tab. Step 2 – Open the Privacy & Security panel. Step 3 – Turn on the “Camera” permission there. Step 4 – Inside, you will find a list of apps that have requested permission for your phone’s camera. Step 5 – Open the “Camera” of the specified app

See all articles