|
PHP & JavaScript World Domination Series: Storing data in the client.
The generic model:
Using frames you can refresh a given frame without reloading the others, this is good for minimizing (c/s) transfers. Our model is based on the following scheme:
- A "master" file which defines the frameset.
- A "loader" frame.
- A "display" frame.
In our scheme, the loader frame refreshes itself each "x" seconds - the idea is to store data in the "master" file allowing the "loader" frame to ask the server only for data that the client has not received yet. We use timestamps to mark messages, news or transferable items and know which ones need to be transfered to the client and which ones not, we use PHP4 sessions to store the "last timestamp" in the client so it is visible in the server. When the "loader" receives data it is stored in the "master" file (note that "master" is heavy but it is transfered only once) then it makes the display frame refresh. To be even more optimum we make the display frame as short as possible, the frame only calls a "display" JavaScript function which is obviously stored in the "master" file, this function uses the data stored in "master" to dynamically draw the frame. Let's review the method:
- A "browser" requests the "master" file. (frameset) The master file is transfered from the server, it defines the frameset and then the frames ("loader" and "display") are transfered.
- The loader frame is parsed in the server, if the client has no "timestamp" session var it gets all the data from the server and generates JavaScript code to store the data in "master". Then we set the "timestamp" session variable.
- The loader frame then generates JavaScript code to make the client refresh the "display" frame.
- The refresh causes the "display" frame to call a "display" function which generates the frame from the data.
- Each "x" seconds we go back to (2)
We can analyze the method as following:
We have 3 files:
| "master" | (very heavy, with display function and storage variables and initial values) |
| "loader" | (light, php code to retrieve data from the server and write JS code) |
| "display" | (VERY light, just a call to a display function in "master") |
Master is transfered only once.
Loader and display are transfered each "x" seconds.
Loader may be big the first time it is called, then it is a very short file
since only the data that the client has not received is transfered.
Display is always the same.
The "nice" display generation is processed in the client so we reduce
the server load.
Are you confused? Let's see an example:
In this example we build a chat room which is not usable yet, we just show how to implement this model, please don't say "why don't you do this and that to the chat room...". You can build a chat room as complex as you want using this model if you find it useful, and remember it is not only useful for chatrooms.
| Comments: | ||
| RE: ehm a relational database for at chat?! | bison | 04/25/04 19:27 |
| Did someone made this working ? | Jean-pierre | 11/21/02 15:15 |
| RE: chat coding | Jainendra | 10/24/02 02:20 |
| storing data | lee | 10/02/02 08:19 |
| Cold Feets from seeing the log below | El Aïd El Othmani Nabil | 09/06/02 07:04 |
| An error in form.php | Elvin Chua | 08/31/02 02:09 |
| The code has an error. | Elvin Chua | 08/31/02 01:24 |
| PHP, MySQL and JavaScript | Elena Iasonos | 08/27/02 11:39 |
| chat coding | Nitin | 08/14/02 04:36 |
| this does not work | Red | 07/24/02 18:13 |
| Manipulating remote files | Boba Fett | 05/21/02 23:20 |
| how will you compare login name & password | sam | 05/03/02 07:47 |
| how to store links in data base.. | koshlesh | 04/07/02 06:17 |
| RE: What is the different of PHP and ASP | rahul b. | 03/18/02 10:08 |
| RE: Getting remote files | Michael Rohde | 03/16/02 00:49 |
| RE: what is CORBA ? | Ndede, George | 02/20/02 22:20 |
| Getting remote files | Jasper Steenkamp | 01/29/02 01:58 |
| exec and the root | Adrian | 12/04/01 16:18 |
| I get the following error.. | umeshkumar | 12/03/01 08:21 |
| session_start bug ! | jarod cinzano, web developper | 10/26/01 09:02 |
| what is CORBA ? | ta anh | 09/15/01 05:38 |
| ODBC for NT | tony | 08/01/01 00:05 |
| variable from php to javascript | Willet | 06/26/01 19:42 |
| What is the different of PHP and ASP | Nicky | 04/14/01 14:26 |
| RE: Web-based Chat | Marco | 03/13/01 10:06 |
| SQL Named Pipes | Johann | 02/13/01 11:17 |
| radiobutton | chandra sekhar | 01/19/01 04:22 |
| RE: Compression | Luis Argerich | 01/12/01 11:19 |
| Compression | Erik Gustavsson | 12/15/00 08:21 |
| Location error | Michael Bykov | 10/30/00 09:49 |
| javascript+php | Aaron | 10/29/00 16:06 |
| RE: A comment on the JavaScript | Dannie M Stanley | 08/26/00 14:02 |
| RE: Web-based Chat | chan | 08/18/00 13:50 |
| RE: Web-based Chat | Jani Kaarela | 08/14/00 13:29 |
| Web-based Chat | le van son | 08/07/00 05:59 |
| A comment on the JavaScript | Jonathan Hurshman | 08/03/00 17:43 |
| RE: I get the following error: | Fredrik Kristiansen | 07/28/00 06:54 |
| Recomendation (please read) | Luis Argerich | 07/25/00 09:34 |
| RE: I get the following error: | hamster | 07/25/00 06:53 |
| I get the following error: | Sascha Endlicher | 07/24/00 21:26 |
|
If you are looking for help, please post on the appropriate forum here. Your questions will be answered much more quickly. | ||


