Im trying to think of the best way to handle real time search for a website. The only solution I can come up with is to keep checking the server every few seconds for something new in the database, but that does not seem very practical to me.
views:
293answers:
6No, it cannot, because MySQL cannot. You need to use other technologies, possibly including a message queue, or a streaming database.
AFAIK, there's no way to tell MySQL to ping your script when something happens there.
Polling seems to be the only plausible solution...
I have not played with it but have noticed that the Symfony framework has introduced "event notification"... basically, every time one part of the app makes an INSERT or UPDATE, it creates an event, and other pieces of code can register to "listen" to events and fire.
That would be all at the PHP level, not the database level, but is I think what you're looking for.
There's a good article about symfony events here: http://www.symfony-project.org/blog/2009/02/21/using-the-symfony-event-system
even if php could how would u show the updates to the user, u will have to query the server to show the results.
and the only way is what you are already thinking of, querying the server every 5 or more seconds,.,,.
As of 5.0.2 MySQL supports triggers: http://dev.mysql.com/doc/refman/5.0/en/triggers.html
But unfortunately I don't know MySQL well enough to know whether you could do anything "useful" in them to notify the app (in Oracle I'd be thinking xp_'s). At very least you could write a row into a single, audit-like table so that you only have to poll in one place.
You could use something like Gearman (which has a MySQL interface) to prod your php code when something new happens. Maybe you could use those events to build a static page with all the newest info, and use polling on the client side to grab that static page.
I've yet to use Gearman at all, though, so the details on such a setup are beyond me.