| Share |
Having spent way more time on this problem than I really should have, I'm going to make sure everyone can actually find a solution instead of useless WordPress support threads.
The Problem
I wanted to export all the data from WordPress using its native export mechanism (located at http://YOURBLOG/wp-admin/export.php), but since the blog I was working on was pretty large (6k posts, 120k comments), I kept getting XML files that ended prematurely and for which xmllint spit out this error:
Premature end of data in tag channel
Upon closer inspection, I saw the XML file ended with a random, yet always fully closed, </item> tag, but was missing the closing </channel> and </rss> tags, as well as a whole bunch of data.
My immediate theory was that PHP was running out of memory. It's also interesting that the number of <item> elements was always divisible by 20, but after looking at the code in export.php, I saw the loop grabbed 20 posts at a time. This revelation made it obvious that the code crashed while processing one of the batches, which only made the out-of-memory theory stronger.
The Solution
After raising the memory in the export.php file itself and verifying the fix, I came up with the following solution that removes the need to modify core WordPress files. Just add this somewhere in functions.php:
1 2 3 4 5 6 7 8 | /**
* Dynamically increase allowed memory limit for export.
*
*/
function my_export_wp() {
ini_set('memory_limit', '1024M');
}
add_action('export_wp', 'my_export_wp'); |
The code above will dynamically set the memory limit high enough for all but unimaginably large jobs to complete. Feel free to adjust this limit if you have, for instance, millions of comments and lots of RAM on the web server.
And there you have it – full exports. Much better, isn't it?
P.S. Some shared hosting providers have PHP set to ignore the directive above, in which case this solution, or no other solution but upgrading your hosting, will do anything.
P.P.S. There is a bug (#15203) in WordPress <=3.3.1, which doesn't properly escape posts that contain CDATA and breaks XML. It is slated for a fix in WordPress 3.4, but if you haven't upgraded yet (it's not even out at the time of this writing), you can still apply the fix manually, like so. My dumps wouldn't validate before the fix, but I've confirmed that they now fully validate after.
Artem Russakovskii is a San Francisco programmer, blogger, and future millionaire (that last part is in the works). Follow Artem on Twitter (@ArtemR) or subscribe to the RSS feed.
In the meantime, if you found this article useful, feel free to buy me a cup of coffee below.
beer planet is a blog about technology, programming, computers, and geek life. It is run by Artem Russakovskii - a local San Francisco geek who is currently pursuing his own projects and regularly enjoys hacking Android, PHP, CSS, Javascript, AJAX, Perl, and regular expressions, working on Wordpress plugins and tools, tweaking MySQL queries and server settings, administering Linux machines, blogging, learning new things, and other geeky stuff.
I usually just use mysqldump.
I've run into the memory/execution time limits when helping someone import them via phpMyAdmin, though. For that I ended up splitting the dump into multiple files and feeding them in one at a time. http://www.webmaster-source.com/2011/09/26/how-to-import-a-very-large-sql-dump-with-phpmyadmin/
Ah, but I wanted to get WXR working – I needed it for validating XML for importing to DISQUS. Of course, if you are doing full DB dumps, that's a whole other problem.
Ah, Disqus. That makes sense.
Here are more ways to fix your WordPress export file for Disqus
http://www.quickonlinetips.com/archives/2012/08/wordpress-disqus-import-export-comments-errors/
Hi there would you mind sharing which blog platform
you're using? I'm looking to start my own blog soon but I'm having a tough time making a decision between BlogEngine/Wordpress/B2evolution and Drupal. The reason I ask is because your design and style seems different then most blogs and I'm looking for something unique.
P.S Apologies for being off-topic but I had to ask!
my homepage … http://www.disque-dur-interne.net
thank you
http://maria-ozawa.us/tag/maria-ozawa/
thank you! Very good
good this post see more details The Best Tips
http://vipgirlfriend.com
Dear Gentlemen!!!My name is Natally, busty BLONDE, HIGH-CLASS COMPANION I really enjoy life and i like to entertain those who can appreciate a sweet girl’s company. I am what you are looking for in VIP COMPANION, I am truly confortable with desires of gentlemen and love to satisfy their needs! If you would like to melt the stress away, or to have a good company for private parties i am your best pick
Perfect blog with awesome information. Thanks for sharing this usefull stuff with us.
Perfect blog with awesome information. Thanks for sharing this usefull stuff with us.
I just stumbledupon this web blog and found it full of information. Thanks to author for sharing all these contents with us. Thanks