Disqus WordPress Import Hangs
We recently needed to migrate a large WordPress site’s comments to Disqus. Disqus offers two methods of importing comments: their plugin “export” function and a WXR import function.
Unfortunately, neither worked for us. The WXR import process is horrible; if it fails processing it simply says “Error parsing import” instead of returning any useful information. The Disqus WordPress import simply hangs; the plugin would spin through its Ajax calls saying “Importing comments from post #X” for a minute and then all progress halted.
In debugging the hanging plugin, we looked at the Ajax results and saw that the error returned to the WordPress UI (which was cleverly not displayed to the administrator so as to prevent debugging the problem) indicated the API call to Disqus was timing out.
The WordPress WP_Http object used by the Disqus plugin has a default timeout of 5 seconds, which was insufficient for even the tiny batches of comments the plugin sends to Disqus. We therefore made a code modification to Disqus’ wp-api.php in order to set the timeout to 60 seconds. This allowed us to stream through all 5,000 comments without an error.
While we have submitted this patch to Disqus, it appears they have plenty of pull requests on github that are ignored. So, without further delay, here is the modification to fix this problem. Simply add the highlighted line below in the import_wordpress_comments function in lib/wp-api.php.
function import_wordpress_comments(&$wxr, $timestamp, $eof=true) { $http = new WP_Http(); $response = $http->request( DISQUS_IMPORTER_URL . 'api/import-wordpress-comments/', array( 'method' => 'POST', 'timeout' => 600, 'body' => array( 'forum_url' => $this->short_name, 'forum_api_key' => $this->forum_api_key, 'response_type' => 'php', 'wxr' =>; $wxr, 'timestamp' => $timestamp, 'eof' => (int)$eof ) ) );
Philipp
January 28, 2014 @ 1:26 am
Thanks, that tiny line just cured my headaches. Hope Disqus will implement this soon – their support seems to be questionable slow…
alejo
March 21, 2014 @ 6:54 am
Thank you!!! This simple line code helped me lots!! Thank you very much
Sandra
October 19, 2014 @ 6:02 am
I remember there was a way to start the export from a certain post. (Useful in my case, I have more that 25000 posts and want to start the export at post 25000.)
Can you maybe help me out?