Solved

Server->Client communication with php/mysql/jquery

Posted on 2010-11-08
4
481 Views
Last Modified: 2012-05-10
Here is what I am trying to make happen:

Anytime there is an update to a certain variable in my database, I would like that new variable to be sent to any client logged into my site and automatically update asynchronously on their page.  Is there a way to asynchronously have the client's browser be constantly checking that variable/variables in the database to see if they have changed with PHP/JQuery?  What is the best way to handle something like this?
0
Comment
Question by:ncotherman2
  • 3
4 Comments
 
LVL 6

Expert Comment

by:ramelong
ID: 34086947
To develop a, efficient method, firstly there some things to know:
- How these variables are updated?
- How you currently know who is logged and who don't?
- These variables to e updated at client side: in which language are working? In javascript?

But on the other hand you may check these variables in several ways:
- Every time the page is loaded (or reloaded).
- With a timer in javascript (unrecomended on IE because of the "tick" sound).
- With a timer in javascript that check a php program into a layer. This program must have to update the variables.
0
 

Author Comment

by:ncotherman2
ID: 34088160
The database variables are updated by other users on the site.

Yes I currently know who is logged on.

Right now I am retrieving the variables with php.


So in order to be constantly checking these variables I would need to have a constantly running Javascript loop?  Wouldn't that significantly affect performance?
0
 
LVL 6

Accepted Solution

by:
ramelong earned 500 total points
ID: 34088297
Well, depends on the delay between readings... and the amount of logged users.

If these variables aren't required until the reload, the best you can do is read them at the begining of the PHP program. In any other case, you need a timer triggered reader...

In order to update javascript variables, needed to modify vehaviours on the client, a practical way is to linking the reading action to a button action, for instance, you may read the variables  (with AJAX) every time the user clicks on the icons or buttons (for this you may use the onClick event in those elements).

Remember that PHP variables are used at server side, and javascript variables are used at client side.
0
 
LVL 6

Expert Comment

by:ramelong
ID: 34093383
Good luck with your project!
RA
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

These days socially coordinated efforts have turned into a critical requirement for enterprises.
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

785 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question