o / sitemap-php

Library for generating Google sitemap XML files
MIT License
300 stars 177 forks source link

Doesn't truncate the destination file on regenerating sitemap #14

Closed duzun closed 8 years ago

duzun commented 8 years ago

When regenerating sitemap, it writes over old files without truncating them in advance. As a result I get broken XML.

End of XML file

o commented 8 years ago

Hi Dumitru,

I never tried this scenario. I'm clearing directory before generating sitemaps. May be you can add a rm -rf line, if you creating sitemaps with cron from bash.

duzun commented 8 years ago

rm -rf is not working in my case, becase the folder also contains other files, but I already implemented a workaround by removeing files starting with sitemap-part-*.

It took me some time to find the issue, first webmaster tools were complaining, then I was trying to find the syntax error, but couldn't find it as the sitemap had been regenerated, so I thought there is something wrong with accessing the files by bots... (long story)

I guess there are other people experiencing similar issues, as it is not obvious from README what is the exact behaviour. I was expecting it to fopen('sitemap-part-1.xml', 'w'), which would truncate the file.

I suggest to at least add a note to README about this behaviour.

o commented 8 years ago

Hello again!

Just added a note about this behaviour. I'm also noted that adding this functionality as a feature to myself.

Thanks!

duzun commented 8 years ago

Great! :-)