Magento Sitemaps, Cron Jobs and Migraines

Last week I was asked to product a new set of sitemaps for our Magento store.

I logged into the Magento Admin panel, navigated to Configuration > Catalog > Google Sitemap, updated the time under Generation Settings and  clicked Save Config. Task complete or so I thought.

After the time had passed, I logged into the server and verified that the sitemap file was a week old. I deleted the file, repeated the steps and check again. No file was created.

This is when I thought to check the timezone for the site (Configuration > General > General under Locale Options). Sure enough, it was two hours behind us.  So, once again, I repeated the steps, putting a time in two hours from now. Still no file.

Time to pull out the big debugger (Yeah, I’m not sure what that means either).

I soon realized that several parts of Magento are at play here. First, in defining the sitemap settings the first time, the location and name of the file are committed to the database and don’t appear to be surfaced in the admin panel. You can find/edit them in the table SITEMAP. The SITEMAP_TIME column indicates the time it was last generated.

Secondly, Magento’s cron settings define the building of a task list at regular intervals for the next number of minutes (Configuration > Advanced > System under Cron). If you aren’t scheduling your sitemap generation far enough in advance, it won’t be picked up. You will also want to set the Success History Lifetime and Failure History Lifetime to a long enough period to diagnose issues. If the log is purged too soon, it can’t help. I’ve set ours to 1440 (one day in minutes).

Pop open the CRON_SCHEDULE table to see what is happening. Every x number of minutes, as determined by your Generate Schedules Every setting, you should see new rows appear in your CRON_SCHEDULE table. Look for the ones with JOB_CODE set to sitemap_generate. If you aren’t seeing new rows appear there, odds are your crontab isn’t set to call Magento’s cron script.

Keep in mind, there are three possible time settings involved. The timezone for your Magento install, the time recorded in CRON_SCHEDULE and SITEMAP tables are UTC time and if you are checking the file timestamps, they are in your server’s timezone.

Everything makes a certain amount of sense now but when you are dealing with several timezones and multiple components, it can be a little confusing until you understand how everything plays together.

Leave a Reply

Your email address will not be published. Required fields are marked *

7 − = four

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>