Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Server->Client communication with php/mysql/jquery

Posted on 2010-11-08
4
Medium Priority
?
506 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 2000 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
By, Vadim Tkachenko. In this article we’ll look at ClickHouse on its one year anniversary.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

926 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