Disqus problem with wordpress “unable to connect to the disqus api servers”

I recently installed Disqus plugin for WordPress; however, I have been receiving this message “unable to to the servers.” By looking into the source code, it looks like is the ! more specifically the _dsq_curl_urlopen() function, but I did not investigate this error further. As fortunately, we can easily switch to the alternative function _dsq__urlopen().

– open /wp-content/plugins/disqus-comment-/lib/api/disqus/url.php and comment curl code :

 * Wrapper to provide a single interface for making an HTTP request.
 * Attempts to use cURL, fopen(), or fsockopen(), whichever is available
 * first.
 * @param	string	$url		URL to make request to.
 * @param		$postdata	(optional) If postdata is provided, the request
 *								method is POST with the key/value pairs as
 *								the data.
 * @param		$file		(optional) Should provide associative 
 *								with two keys: name and field.  Name should
 *								be the name of the file and field is the name
 *								of the field to POST.
function dsq_urlopen($url, $postdata=false, $file=false) {
	$response = (
		'data' => '',
		'code' => 0

	if($file) {
		extract($file, EXTR_PREFIX_ALL, 'file');
	if(empty($file_name) || empty($file_field)) {
		$file_name = false;
		$file_field = false;

	// Try curl, fsockopen, fopen + stream (PHP5 only), exec 
	if(function_exists('curl_init')) { 
		if (!function_exists('curl_setopt_')) {
			function curl_setopt_(&$ch, $curl_options)
				foreach ($curl_options as $option => $value) {
					if (!curl_setopt($ch, $option, $value)) {
						return false;
				return true;
		_dsq_curl_urlopen($url, $postdata, $response, $file_name, $file_field);
	} else if(ini_get('allow_url_fopen') && function_exists('stream_get_contents')) {
		_dsq_fopen_urlopen($url, $postdata, $response, $file_name, $file_field);
	} else {
		// TODO: Find the failure condition for fsockopen() (sockets?)
		_dsq_fsockopen_urlopen($url, $postdata, $response, $file_name, $file_field);
	//open urls with fsockopen
	_dsq_fsockopen_urlopen($url, $postdata, $response, $file_name, $file_field);
	// returns  with keys data and code (from headers)
	return $response;

– A more compatitble way to do this is to connect wp_remote_post.

**Update: The plugin was tested with curl 7.24, PHP 5.3.10 and Nginx 1.0.12.

  • Pingback: @Artoha @disqus :: GadElKareem()

  • bttestingusr

    Very useful info, thanks.

  • yagudaev

    Worked like a charm. Thank you :).

  • sundher

    Friend I have a problem in disqus unable connect disqus server how to slove please help me..

  • Thanks for sharing this. I may never have figured this out otherwise.

  • Thanks… I love u man .. you saved me! ahaha

  • damienlepage

    Thanks! I wish disqus includes this in their troubleshooting guide.

  • coopeg

    Not work for me

  • robertoadmin

    I already did this

  • robertoadmin

    Sorry, i already did this fix but it doesn’t work

  • infagalaxo

    Thanks again man. Now I am feeling great with Disqus.

  • quang2o12

    Tks so much,

  • why i add this comment but it still does not work?

  • Matthew Kooshad

    simply commenting out that block and adding that one line doesn’t work for me also.

  • Unable to connect to the Disqus API servers PLS HELP

  • Thanks so much! It’s work for me 😀