Export comments to Disqus not working?

Symptom:
You just installed Disqus commenting system and need to export existing WordPress comments to the service. However, the export “hangs” in WordPress admin leaving that wait icon spinning forever.

Cause:
When clicking that export comments button in WordPress admin Disqus plugin it calls WordPress once for every post. The WordPress server then makes a HTTP-request to Disqus and that request has a timeout setting by default of 5 seconds. If it timeouts, the export “hangs”.

Solution:
You need to increase the WordPress HTTP request timeout value. It defaults to 5 seconds in /wp-includes/class-http.php. Below is the WordPress code to set defaults (line 70 in WordPress 3.8):

$defaults = array(
    'method' => 'GET',
    'timeout' => apply_filters( 'http_request_timeout', 5),
    'redirection' => apply_filters( 'http_request_redirection_count', 5),
    'httpversion' => apply_filters( 'http_request_version', '1.0'),
    'user-agent' => apply_filters( 'http_headers_useragent', 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' ) ),
    'reject_unsafe_urls' => apply_filters( 'http_request_reject_unsafe_urls', false ),
    'blocking' => true,
    'headers' => array(),
    'cookies' => array(),
    'body' => null,
    'compress' => false,
    'decompress' => true,
    'sslverify' => true,
    'sslcertificates' => ABSPATH . WPINC . '/certificates/ca-bundle.crt',
    'stream' => false,
    'filename' => null,
    'limit_response_size' => null,
);

As you can see there is a filter named http_request_timeout that can be used to alter this value. Put snippet below in a plugin or theme:

function custom_timeout($current_timeout)
{
    // New timeout.
    return 30;
}
add_filter('http_request_timeout', 'custom_timeout');

Leave a Reply

Your email address will not be published. Required fields are marked *