Jump to content

Recommended Posts

I know mysql provides some trigger possibilities but I wonder if I could do something more with it.

I would like to trigger command (php file) when certain values are set. Let say I am looking for certain values in my database to match predefined values which would trigger that file to run.

I know I can have php file checking values in the database and if these values match to go on with the remainder  of the execution or exit after the check if the values don't match but I think that doing it directly from database would be more efficient since I would have to have few cron jobs runned at intervals to make sure I eventually get all the values to match and can execute my action.

Link to comment
https://forums.phpfreaks.com/topic/228830-mysql-trigger-question/
Share on other sites

Even if you could do this, it is not a good idea. During the execution of a trigger, the tables being affected are locked (at least the pages containing the rows being modified) and will remain locked until the trigger completes. If you started an external process, and that process hung up, the server could hang. If the process you started, tried to access the data that fired the trigger, it would not be able to because the data is locked. It will wait for the lock to be released, the lock will not be released until after the process is finished, and the process can't finish until the lock is released. This is called a "Livelock", the database server cannot tell that the process will never continue, so it is not a Deadlock. The process would hang until you killed it, which would likely cause the transaction to rollback and the data will NOT be updated. Triggers were invented to insure database integrity. They should not be used for application code. They must be fast and efficient code.

 

A cron job is your best choice. A well written, efficient script will should not be a problem for the server. 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.