Disqus WordPress Import Hangs

disqusWe 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
                )
            ) 
        );