Answer the question
In order to leave comments, you need to log in
How to run php script when changing mysql database?
There is a task: data will be added to the mysql database, by hand (from some kind of shell). When changing a column or cell, a php script should be launched that sends data via TCP to a remote server. The search gave the answer that it is not possible to run the script from mysql. I understand that the first question is: "something is somehow not human, can't it be done differently"? It is impossible because that is how the customer sets the task. Putting a task in cron to pull the database for changes once a minute is not suitable, because the script must be executed immediately after the database is updated - the absence of a time interval between the update and the launch of the script plays a big role. During the day, a minimum of data will get into the database, but the reaction to changes should be instantaneous.
Question: Is it possible to solve the problem in this way? Maybe another base or something. I'm starting to learn Python, maybe there are solutions using Python?
Update: Why doesn't anyone write about demons?
Answer the question
In order to leave comments, you need to log in
The solution is this: I wrote a script where a cell in the base table is checked in an endless while (true) loop. When there is a change, there is a corresponding reaction. The script was launched on the server from the console with the command "php -f path/to/file.php &". The script spins endlessly, but the server loads both the process of the file itself and mysqld by about 60 percent. I didn’t understand it, I added a sleep (1) pause to the cycle, as a result, the load dropped to zero. Fortunately, I do not need to check more than 1 time per second.
See UDF + triggers.
stackoverflow.com/questions/1467369/invoking-a-php...
Let "some kind of shell" pull this script after writing to the database.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question