How does one create a PHP script that checks the MySQL row consistently and if a set query is matched, it starts an event, such as sending an email?
For example, on query match Fire
start email:
To: me@me.com
From: php@trigger.com
Subject: Set query met, auto email complete.
It would be around MySQL5. I'm stuck on this. Am I best to do it in Perl or similar? Perhaps it could also email various users? (This isn't the hard bit. :P)
Using cron
or similar scheduler involves polling , which works but is brute force and ignorance . I can't recommend it: there's a time delay between when the row changes and when cron executes the checking program; repeated checking is a waste of resources.
The elegant solution is database trigger, see Using Triggers and Can triggers call an external application through a UDF? . You will get an event whenever your table row is on fire or something, and your email sending program is called immediately.
If you want to use Perl, Email::Simple
/ Email::Sender
is nifty.
You can use PHP or Perl or any other programming language you like.
Create a cronjob to execute your script every X hours.
For example php queryDatabase.php
.
That's it.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.