php-cron – schedule jobs to run by the second and more

Yet another challenge, mostly like all other developers, ours at Saturn too believed that scheduled jobs could be run to the lowest frequency at every minute. This stands true if the job is handled only by *nix cron or by windows scheduler. For even further control one should write a Sleep-And-Run. I used to do this in shell script for most of my requirements. Just the other day some one challenged me to get done with one similar in php.

The outcome is a crude one, ServiceManager, which runs based on a configuration file and its run frequency. Best not to change the frequency or your configuration would never support anything less than the frequency as well as will only support multiples of the frequency. The configuration file is the famous ini file format with item names in square brackets, with configuration on two lines. The sample attached ServiceManager.ini should give an idea.
Continue reading “php-cron – schedule jobs to run by the second and more”

MySQL: Optimize all tables; Run using cron

I was looking for a optimize table script and finally stumbled upon some code which could be salvaged into a shell script. The full code is reproduced here for future reference.

#-- I usually add the root username and password to the ~/.my.cnf
MYSQL_CMD='/usr/bin/mysql '
$MYSQL_CMD -e "SELECT concat('OPTIMIZE TABLE ',TABLE_SCHEMA,'.',TABLE_NAME,';') as cmd FROM information_schema.TABLES WHERE TABLE_SCHEMA NOT IN ('information_schema','mysql') AND Data_free > 10 AND NOT ENGINE='MEMORY' INTO OUTFILE '/tmp/cmd.sql'"
$MYSQL_CMD < /tmp/cmd.sql
rm -f /tmp/cmd.sql