1

I have a kind of application that must query a db at periodic intervals..I want to use push technology such that when the database is updated, the server sends data to the client..How is it possible to implement that ?

4
  • 3
    PHP is not appropriate for this, as you need to keep a request open for each client. Commented Jan 24, 2012 at 14:15
  • 2
    Or, you fake it by polling the server with JavaScript every few seconds. It is not a true push, but depending on the timeliness of the data, that may be okay. Commented Jan 24, 2012 at 14:21
  • This needs way more context since it depends a lot on the rest of the architecture, the type of client and the event that can trigger an update. Commented Jan 24, 2012 at 14:22
  • I peg to disagree with PHP not being suitable - there is nothing in PHP, that makes long poll AJAX and friends unfeasable, in fact I do it all the time (update the seating plan in a ticket-selling app, when a seat has been sold at another boxoffice) Commented Jan 24, 2012 at 14:30

2 Answers 2

3

We do this quite regularily - our way is "long polling":

  • From the client, start an async poll request
  • On the server, just keep this poll request waiting for e.g. 30secs (send a \0 or a blank every couple of seconds, if you need really long times)
  • When the database is updated, create some sort of event on the server side
  • When such an event is detected by a long-poll handler, write the resulting client notification and end the request
  • On the client, when an asyn poll ends, check it for notifications, work on them, then start the next long poll
Sign up to request clarification or add additional context in comments.

3 Comments

Typically Apache, typically LAMP stack, typically Ubuntu Server LTS
And you don't have trouble with long polling stealing your processes?
No, no problems if you follow some simple rules: 1. Longpoll handlers should not use much memory - keep them as basic as possible until the really do some work. 2. have an eye on your connection count and tune your apache if necessary
-2

You can implement a web service/API using SOAP in PHP.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.