我想分割我的sitemap.xml,因爲Google網站管理員工具只允許sitemap.xml小於50k的URL。我將以下代碼放置在: app \ code \ local \ Mage \ Sitemaps \ Model \ Sitemap.php如果該文件包含超過50k個網址,則會拆分sitemap.xml。Magento,Split sitemap.xml和cron作業
public function check_counter(&$io) {
static $counter;
$counter++;
$tRec = 50000; // total record per file
if (($counter % $tRec) == 0){
$io->streamWrite('</urlset>');
$io->streamClose();
$filename = preg_replace('/\.xml/', '-'.
round($counter/$tRec).
'.xml', $this->getSitemapFilename());
$io->streamOpen($filename);
$io->streamWrite('<?xml version="1.0" encoding="UTF-8"?>'."\n");
$io->streamWrite('<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">');
}
一切工作正常,如果我從Magento管理面板手動生成站點地圖。這將創建2個文件:sitemap.xml的(50,000 URL)和網站地圖 - 1.XML(12,312網址)
我已經設置了cron作業每天晚上生成網站地圖。問題是cron的工作似乎沒有遵循代碼。它生成2個文件:sitemap-1.xml(我不知道有多少,但肯定超過50,000個網址,因爲谷歌給我一個錯誤,說我在這個文件中有太多的網址)和sitemap.xml (幾百個網址)
代碼有什麼問題?或者我的cron工作出了什麼問題?
編輯:
我把
$this->check_counter($io);
每個
$io->streamWrite($xml);
後
public function generateXml()
很難說沒有看到你從哪裏調用check_counter。 –
默認Magento站點地圖擴展被竊聽(非常慢/內存消耗)。 我建議你使用這個擴展名(它支持拆分): http://www.magentocommerce.com/magento-connect/xml-sitemap-generator-splitter-7228.html – WonderLand
它甚至不能用於我手動。 –