Sr. Web Developer
mediabistro.com
US-NY-New York

Justtechjobs.com Post A Job | Post A Resume

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:

  1. 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.
  2. 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.
  3. The loader frame then generates JavaScript code to make the client refresh the "display" frame.
  4. The refresh causes the "display" frame to call a "display" function which generates the frame from the data.
  5. 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.

Next Page

[Page 1]  [Page 2]  


Comments:
RE: ehm a relational database for at chat?!bison04/25/04 19:27
Did someone made this working ?Jean-pierre11/21/02 15:15
RE: chat codingJainendra10/24/02 02:20
storing data lee10/02/02 08:19
Cold Feets from seeing the log belowEl Aïd El Othmani Nabil09/06/02 07:04
An error in form.phpElvin Chua08/31/02 02:09
The code has an error.Elvin Chua08/31/02 01:24
PHP, MySQL and JavaScriptElena Iasonos08/27/02 11:39
chat codingNitin08/14/02 04:36
this does not workRed07/24/02 18:13
Manipulating remote filesBoba Fett05/21/02 23:20
how will you compare login name & passwordsam05/03/02 07:47
how to store links in data base..koshlesh04/07/02 06:17
RE: What is the different of PHP and ASPrahul b.03/18/02 10:08
RE: Getting remote filesMichael Rohde03/16/02 00:49
RE: what is CORBA ?Ndede, George02/20/02 22:20
Getting remote filesJasper Steenkamp01/29/02 01:58
exec and the rootAdrian12/04/01 16:18
I get the following error..umeshkumar12/03/01 08:21
session_start bug !jarod cinzano, web developper10/26/01 09:02
what is CORBA ?ta anh09/15/01 05:38
ODBC for NTtony08/01/01 00:05
variable from php to javascriptWillet06/26/01 19:42
What is the different of PHP and ASPNicky04/14/01 14:26
RE: Web-based ChatMarco03/13/01 10:06
SQL Named Pipes Johann02/13/01 11:17
radiobuttonchandra sekhar01/19/01 04:22
RE: CompressionLuis Argerich01/12/01 11:19
CompressionErik Gustavsson12/15/00 08:21
Location errorMichael Bykov10/30/00 09:49
javascript+phpAaron10/29/00 16:06
RE: A comment on the JavaScriptDannie M Stanley08/26/00 14:02
RE: Web-based Chatchan08/18/00 13:50
RE: Web-based ChatJani Kaarela08/14/00 13:29
Web-based Chatle van son08/07/00 05:59
A comment on the JavaScriptJonathan Hurshman08/03/00 17:43
RE: I get the following error:Fredrik Kristiansen07/28/00 06:54
Recomendation (please read)Luis Argerich07/25/00 09:34
RE: I get the following error:hamster07/25/00 06:53
I get the following error:Sascha Endlicher07/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.

Add A Comment:

Name:

Email:

Subject:

Message:

To reduce spam posts, messages are now manually approved

You are not [logged in]. That means your account will not get credit for this post.