Answer the question
In order to leave comments, you need to log in
"Subscribe" to an event in the database
Hello!
The problem is this: there is a php application that displays information from the database. The base is filled with a desktop application in Delphi. I need to respond to the appearance of a new record in the database: display it to the user. Now it is implemented through a timer + ajax. It is impossible to receive some kind of signal from an application that adds information to a table. The node.js option is also not very suitable. Are there other ways, more cultural?
Answer the question
In order to leave comments, you need to log in
Probably you need this:
http://habrahabr.ru/post/69457/
Allows you to keep a permanent connection between the client and the server :)
I don’t know how much this can help in your case, but Interbase/Firebird have built-in event support — Overview of Firebird events
No. There are long polling and websocket, but they will not help here, because. The database will not send a message (and the socket will not be held). Only if the “timer” is transferred to the backend script, but there is no point in this case, an extra complication.
And if you don’t bother, and after sending information from delphi to the database, make a call to the necessary php function (by the last id or something else), what will this new object receive and display to the user?
Yes, not very beautiful, but the least expensive in terms of development
Here the question is not very clear, but what is available to you from PHP? Is this a web server script? Can it be running all the time, or is it periodically synchronous with requests from the browser?
If it can be run constantly, then above groaner gave you a link to the description of events in FireBird, the events themselves on the server side can be posted from a table trigger on insert, caught in PHP and further in meaning.
But in general, for FireBird / Interbase, on request from the browser, you can pull from the database not even records since the last one was read, but the value of the generator that is used to auto-increment id in the table - this will be easier for the database and faster. If the generator has changed, then send a request for new records.
You can also make a “stored procedure” on the server side that returns new data if it appears - most batch queries through a stored procedure will be faster than sequentially submitting them from the client (we get rid of the prepare series for each request, because " the storage" itself is "prepared" at the time of compiling blr). Pass the last read id to the procedure, and it will compare it with the generator itself, and if something has changed, then climb into the table for the records and give them to the client, otherwise give an empty result.
In the same way, you can keep track of changed records (not just added ones): we make another field in the table that is updated from the generator both during insert and update, and we monitor changes and inserts already by this separate generator.
PS Of course, if your database is not heavily loaded, then monitoring the generator can be omitted, always simply querying the table directly for new / changed records.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question