1

I am working on a website, and I need to have real-time updates..

All I need to do is have the client echo the row when it is added at the exact time..

I am pretty good in PHP, and I can do simple queries in SQL..

What do you suggest?

3
  • are you asking when you can check if a table has been updated? Commented Apr 4, 2011 at 22:19
  • No, I am asking how I can check if the table has been updated after the page is loaded.. so the client can stay on the page as long as they'd like and still receive updates without having to refresh. Commented Apr 4, 2011 at 22:21
  • Duplicate of stackoverflow.com/questions/3972065/… Commented Apr 4, 2011 at 22:35

3 Answers 3

2

I'm pretty sure you're going to have a hard time getting around polling for this type of scenario. You will probably have to continually poll the data store.

Tips: Use server side caching and use ajax

Sign up to request clarification or add additional context in comments.

1 Comment

As Joe said, you have to poll. Now, you can definitely poll via an Ajax query, which would make it almost imperceptible to the user, but poll you must.
0

You're looking for a comet-like system. I'm familiar with a comet-clone... it uses a table for subscriptions and pushes. In your case you'd want to use a stored procedure. In the stored procedure, when an insert is done to that table and it is successful, it would insert into the comet message table. A service will checking this message table every second (or however often you want). Once it sends a message, it remove the message from the table.

This extra table removes all the overhead off of the table you are inserting into, and instead puts it onto the comet message table which should never have more than a handful of rows to report, since it is being wiped after the messages are reported.

Comments

0

What you are looking for is a method of subscribing to a channel. You can accomplish this with Push (Long poll) - so when the page loads, you request the new items. Server then does the loop every 1 second for 30 seconds. If it finds new rows, server spits them out, and you do another ajax request with different timestamp.

Other technique is WebSockets where you get to subscribe to a channel and you're done. But to implement it could be harder than the first method.

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.