Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Display WAITING on webpage using PHP Ajax & mysql

Posted on 2012-04-11
5
Medium Priority
?
468 Views
Last Modified: 2012-06-20
I have only started looking into this but it could be complex...

I want to be able to display a WAITING screen on a php page whilst the value of ready in a mysql database is 0. When I update the mysql READY field to 1 the waiting screen goes.

The goal eventually will be:
User click to voting.php
User sees waiting box
When I want the user to start voting the first question shows.
User can then complete all questions to the end.

Do you have any thought on this??

I thought perhaps have an ajax call every second until ready =1...

Any other ideas.

Thanks

Steve
0
Comment
Question by:Steve Tinsley
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 23

Expert Comment

by:basicinstinct
ID: 37834750
that's how i'd do it - poll the server every N seconds just like you say.
0
 

Author Comment

by:Steve Tinsley
ID: 37839814
The system im developing may have 100 browsers all on the waiting page at the same time.
This would mean 100 browsers all polling the mysql db every second.

Is there a better way of doing this?

I have been looking into LONG POLLING but dont quite understand it yet. Would this be the way to go? How different is this to a standard ajax call??

Steve
0
 
LVL 23

Expert Comment

by:basicinstinct
ID: 37839864
yes, i think every 1 second is a lot (which is why I said every "N" seconds), but you know your data and maybe you need that kind of instant feedback.

i have looked into this from time to time in the past and always ended up sticking with polling... server push / comet / long polling whatever you want to call it always involved leaving the connection permanently open... so instead of ever N seconds you have this connected open permanently.

if you could increase the interval you will reduce the load

in the past we have looked at how the page design can aid in perceived performance - rather than a loading screen where the user has nothing to read or do can you present the user with some reading (voting instructions or something)...
or failing that give them a quote of the day, pacman game etc :)

my last solution could poll easily for 20 seconds (slow service call) so we put the region that would be updated at the bottom of a screen which would take the user a minute to work through - they wouldn't even notice the slow service call.
0
 

Author Comment

by:Steve Tinsley
ID: 37839978
The system im designing needs to start the voting for possibly 100 browsers at the same time (or within a fraction of a second).

From what ive read, the system may work like this...
What do you think?
JS
    function waiting(){
        $.ajax({
            type: "GET",
            url: "waiting.php",
            async: true,
            cache: false,
            timeout:300000, /* Timeout in ms */

            success: function(data){
                                if (data == 1){
                                            load vote question
                                 }
                                 else
                                 {
 				            $.blockUI();  /*  display please wait*/
                                            waiting()', /* Try again */
                                 }
            },
        });
    };

Open in new window



PHP
connect to db
$wait = 0
while $wait = 0 {
           query database
           sleep(1);
}
echo $wait

Open in new window

0
 
LVL 23

Accepted Solution

by:
basicinstinct earned 2000 total points
ID: 37840339
rather than checking the db for each request that comes in couldn't you check the db once every second and then cache that value somewhere on the server where all requests could access it. that would take the pressure off your db at least (tho obviously the web server will still need to easily support 100 concurrent connections)

five minutes seems like a pretty long timeout when you are expecting fast responses... maybe better to let the user know sooner that there is a problem...

depending how accurate the start time needs to be i guess you will need to consider latency, geographic distance from the server, bandwidth (dial up users).
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Introduction Chart.js, used properly, can visually add a difference to your charting applications. It engages your visitors and allows them to interact with data they otherwise wouldn't be able to without expensive and complicated systems. For this…
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

718 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