JQUERY polling

Published on October 28th, 2012 | by Sheeraz

2

Achieving Short Polling with Jquery & PHP

Being a PHP developer, I am sure this is the most biggest challenge faced while populating data in real time. As PHP relies on a server, Apache mostly, a continues concurrent connections opened will slow down the server and limit its resources. This is due to the blocking architectural of Apache.

While looking into various methods from which we can actually achieve real time data, we can use polling, short polling ofcourse as long polling is literally hard to achieve with Apache.

Short polling is a method where client sends a request to the server and server responds, it is a basic HTTP request. This request can be set to initialize within a time interval to minimize server overload. for this matter we are going to use a jquery plugin that you can find at http://www.eslinstructor.net/smartupdater3/ known as smartupdater.

so lets begin with the file structure.
1- index.php [file]
2-poller.php [file]
3-scripts [folder]
      – jquery-1.8.2.min.js [file]
      – smartupdater.4.0.js [file]
so lets start to build the pages.
1- index.php

  •  Initialize the script in the header part, we give 1 second interval. Moreover the data is to populate in a div labeled in ID as “livedata”.

  •  now that we have initialized, lets make the div in the <body> portion that will hold the live data.

Full source code looks like below for index.php 

lets start with the next file.

 2- poller.php

Here we are not going to do much, just asking PHP to echo out current time. If you want you can run mysql_queries and get the result too.

now that both the files are ready lets run it. Have a look it in the demo.
DEMO | DOWNLOAD 

Hope you like this tutorial and hope to see this in your work, Please leave your feedback.

Thank you.
 

Tags: , , , , , ,


About the Author


2 Responses to Achieving Short Polling with Jquery & PHP

  1. I appreciate the good work you are doing! I’ve really enjoyed reading it. You’ve arouse me a great interest. I’ll investigate it more. Keep up doing it!

  2. Nice! How can I sign up for RSS to your blog? Thanks!

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Back to Top ↑