October 03, 2010

As covered in our last article, you should have a “cron job” (crontab) set up to run Magento’s cron.php file every so often (15 minutes or so is fine) via PHP directly on the server to take care of housekeeping tasks that keep Magento working well. Some other tasks, like updating tracking / inventory status, sending out newsletters, and other miscellaneous things also require that the crontab be properly set up, so if you haven’t taken care of that yet, please see the setup guide here, or contact support@nexcess.net and we can help you set it up.
Once your crontab is properly installed and configured, you might be curious as to what it’s actually doing behind the scenes, or you might want to verify that something did / did not happen, and when. Since Magento lacks this arguably critical information, we’ve whipped up a simple PHP script that can show you what’s scheduled, what’s running, and what already ran, along with all the other information hiding in the ‘cron_schedule’ table of your Magento database. Simply drop the script (linked to below) into your base HTML directory for Magento (usually this will be your “public_html” directory), change the file extension to “.php” instead of “.phps”, and load it up in your favorite browser.
You should see something like this:
Mage Cron
All of the fields should speak for themselves.
Copy and save the following PHP script.
[code language=”php”]
// Parse magento’s local.xml to get db info, if local.xml is found
if (file_exists(‘app/etc/local.xml’)) {
$xml = simplexml_load_file(‘app/etc/local.xml’);
$tblprefix = $xml->global->resources->db->table_prefix;
$dbhost = $xml->global->resources->default_setup->connection->host;
$dbuser = $xml->global->resources->default_setup->connection->username;
$dbpass = $xml->global->resources->default_setup->connection->password;
$dbname = $xml->global->resources->default_setup->connection->dbname;
}
else {
exit(‘Failed to open app/etc/local.xml’);
}
// DB Interaction
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die (‘Error connecting to mysql’);
mysql_select_db($dbname);
$result = mysql_query("SELECT * FROM " . $tblprefix . "cron_schedule") or die (mysql_error());
// CSS for NexStyle
echo ‘


Status>

’;
// DB info for user to see
echo ‘


Nexcess Beyond Hosting

Table Prefix: ‘ . $tblprefix . ”
. ‘DB Host: ‘ . $dbhost . ”
. ‘DB User: ‘ . $dbuser . ”
. ‘DB Name: ‘ . $dbname . ‘

’;
// Set up the table
echo "













";
// Display the data from the query
while ($row = mysql_fetch_array($result)) {
echo "";
echo "";
echo "";
echo "";
echo "";
echo "";
echo "";
echo "";
echo "";
echo "";
}
// Close table and last few tags
echo "
schedule_id job_code status messages created_at scheduled_at executed_at finished_at
" . $row[‘schedule_id’] . "" . $row[‘job_code’] . "" . $row[‘status’] . "" . $row[‘messages’] . "" . $row[‘created_at’] . "" . $row[‘scheduled_at’] . "" . $row[‘executed_at’] . "" . $row[‘finished_at’] . "
";
mysql_close($conn);
?>
[/code]
PLEASE NOTE: This script is designed to be secured for use by site administrators only. If you have any questions, please e-mail support@nexcess.net

Nexcess
Nexcess

Nexcess, the premium hosting provider for WordPress, WooCommerce, and Magento, is optimized for your hosting needs. Nexcess provides a managed hosting infrastructure, curated tools, and a team of experts that make it easy to build, manage, and grow your business online. Serving SMBs and the designers, developers, and agencies who create for them, Nexcess has provided fully managed, high-performance cloud solutions for more than 22 years.


We use cookies to understand how you interact with our site, to personalize and streamline your experience, and to tailor advertising. By continuing to use our site, you accept our use of cookies and accept our Privacy Policy.