I have a cron job running that executes a PHP file which checks a MySQL database for a change. I have this script running every minute but it's very simply query.
Still, is running a cron job like this every minute going to be too hard on the server? Is there a better approach to what I'm doing?
Depending on the query, if it's SQL related only, consider a MySQL event. But it depends on what it does. If PHP code is required to interact with it... events won't help. If it just does some updates in MySQL (like expired user sessions and removing unconfirmed user accounts)... an event will do.
Running every minute is not hard on the server, it depends on what it does. microtime()
execution of the script and log it to a text file with register_shutdown_function()
(you can also memory_get_peak_usage()
). See how long it takes, how much memory it consumes... that will tell you how hard it is on the server.
A simple query like that shouldn't be an issue... most PHP pages make many more calls, and the server can be processing many requests at once. Unless it's a beast of a query, you'll be fine.