For one of the sites I manage there is something funny happening with the server time. The site uses WordPress and I really like the way WordPress $wpdb class works. In a few sites I manage I occasionally have scripts which preform routine functions which effect the content in WordPress. To use all of the WordPress functions you simply add ‘include_once(“wp-load.php”);’ to the top of you PHP script.
To track the time I created the following script and I have set up a CRON Job to run every minute to track the time on the server.
The PHP is:
$query=”INSERT INTO time_track (php_time) VALUES (‘”.date(‘Y-m-d H:i:s’).”‘)”;
By including the wp-load, I have full access to all of the WordPress functions. In this case I am using the $wpdb class which has reduced my code to 3 lines (could be 2 if I typed the query directly into the query function).
The table SQL is:
[cc lang=”SQL”]CREATE TABLE `time_track` (
`id` int(11) NOT NULL auto_increment,
`php_time` timestamp NULL default NULL,
`mysql_time` timestamp NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=latin1[/cc]
This is a great way to have stand alone scripts which interact with the WordPress install. I am sure that the wp-load is adding extra overhead, though it does not matter as only a CRON Job once a minute is calling the script.