Sitemap generation using cron

Hi,

I have run out of ideas. How could I generate sitemap.xml using terminal commands? I have admin controller and action sitemap, but these are available only for logged in administrators. When i run admin/sitemap it outputs all content to browser.

So I have two questions:

  1. How save admin/sitemap output to local xml file

  2. How to run this procedure from terminal

I would be grateful for any help.

did you try this extension ?

also in the extension there’s a link to a post where they discuss it

I took an idea from this topic, but I need sitemap as file, not as dynamic page, because it will contain huge amount of records (512mb php memory limit was not enough)… And I need to generate it using cron.

If you work with a huge amount of records don’d use activerecord, they are really expensive.

In such a scenarion you don’t need either sorting of paging, so feel free to do a simple query like:


Yii::app()->db->createCommand('select id from people')->queryAll();

And then use this id for create the links.

With such a method you will save lot of memory (and much more using query() and reading with the dataReader).

Thanks zaccaria for saving some resources on my server. I’m posting here to say how I solved this problem.

Very simple.

config/main.php




'verysecreturl_sitemap.xml' => 'secret/sitemap',



And crontab line (configured daily)

cd /path/to/webapp; wget example.com/verysecreturl_sitemap.xml; mv verysecreturl_sitemap.xml sitemap.xml

On the same server it downloads (540 MB/s). And now I have static sitemap :)