Could not open socket error

If a user tries to submit a post on my website they encounter the error message 'Could not open socket'

The user is requested to enter in a CAPTCHA, I'm not sure if that's related.
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ray PaseurCommented:
If CAPTCHA is the issue, this article may help.

To have any hope of understanding the issue we would need to see the complete error messages, and we may need to see the code, too.  Please post the URL that shows the failure and give us instructions on how to reproduce the failure.

Thanks, ~Ray
Cosmic_CakeAuthor Commented:
Hi Ray,

Here is the URL

If you fill out this form it will reproduce the error message. The error message doesn't reveal much, just 'Could not open socket error'

I think I will have to post some php files on here.
Patricia Siu-Lai HoCommented:
Hi Cosmic_Cake,

Your form is in

Please check the file is right path and file in form action of your script

<form action="/post-a-story/" method="post">

Patricia / pslh
Protecting & Securing Your Critical Data

Considering 93 percent of companies file for bankruptcy within 12 months of a disaster that blocked access to their data for 10 days or more, planning for the worst is just smart business. Learn how Acronis Backup integrates security at every stage

Cosmic_CakeAuthor Commented:
I cannot find a 'post-a-story' page. I didn't develop the site. I'll keep looking.
Patricia Siu-Lai HoCommented:
Hi Cosmic_Cake

Now I inspect the element of your web page,

It is  stated in this line

<form action="/post-a-story/" method="post">

"/post-a-story/"  it is not specify any file to post to.  

So you get the error.

your web page is inside folder post-a-story/

if the destination file eg. destination.php is in the same folder, you just type

<form action="destination.php" method="post">

Otherwise, if it is in other folder

<form action="../otherfolder/destination.php" method="post">

or  subfolders

<form action="subfolder/destination.php" method="post">

Patricia / pslh
Cosmic_CakeAuthor Commented:
I think I located the file where the problem could be. See Below:

 Plugin Name: Anon Post
 Plugin URI:
 Description: This plugin allows anonymous users to write their own posts using special page. No access to wordpress panel is needed.
 Version: 1.3
 Author: Wojciech Langiewicz
 Author URI:

/* Copyright 2009  Wojciech Langiewicz  (email : wlang(dont spam me)
 * This script is relased under BSD license.

require_once ( ABSPATH . WPINC . '/registration.php' );

//------------------------- start of options section ---------------------------

 * You can change this options to suit you needs.
 * If you want to use reCAPTCHA you need to get API key,
 * for more information see:
 * then click: "Sign up Now!" or log into your account

$anonUserName = 'Anonymous'; // 'name' of anonymous user, don't have to exist
$category = array(1); //this array should contain IDs for categories you want anonymous post to be in, example: array(1,2,4). NOTE: create those categories first, and check their numbers

$captchaEnabled = true; // enable reCAPTCHA (set to: true/false), do not use ' or "
$publickey = '6Lfn18MSAAAAAIaXx1isTq_uCAsuTpT9LY-RICSj'; // enter your API keys here
$privatekey = '6Lfn18MSAAAAAMyD1u1ayJoBAhxFIEj1-mywB1_4';
$enableComments = true; // true if you want to enable comments under posts created with plugin
$my_post_type = 'draft'; // avaiable options: 'publish' for posts to be published directly
                                    // 'draft' if you want to validate posts (by admin for example), post will appear as draft
$enable_css = false;      // set to true/false if you want css or not (css can be edited at the end of this file)
$display_content_after_post_created = true; // set to true/false if you want to show content of page displayed above the form after post is sucessfully created on confirmation page
$use_anonComment = false; // set to true/false if you want to use Anonymous Comment plugin to allow users to comment posts creted with this plugin to be anonymously commented, remember about installing this plugin first

// ---------- end of options, DO NOT CHANGE CODE BELOW THIS LINE ------------


function addAnonContent(){
      global $wp_query;
      global $captchaEnabled;
      global $publickey, $enable_css, $display_content_after_post_created;
      $form = "<br>";
      $this_post_id = $wp_query->post->ID;

      if(get_post_meta($this_post_id, 'anonPost', true) == 'true'){
            //add css:
                  $form .= add_css();

                  $form .= enteredByPOST();
                  $form .= displayFormStart();
                        $form .= '<center>';
                        $form .= recaptcha_get_html($publickey);
                        $form .= '</center>';
                  $form .= displayFormEnd();
            return get_the_content();

            return get_the_content().$form;
            return $form;
      //this should not happen
      //return get_the_content();

function enteredByPOST(){
      global $captchaEnabled;
      global $privatekey, $publickey;
      global $anonUserName, $category, $enableComments, $my_post_type;
      $to_return = '';

      if ((!$captchaEnabled) || recaptcha_check_answer($privatekey, $_SERVER['REMOTE_ADDR'], $_POST['recaptcha_challenge_field'], $_POST['recaptcha_response_field'])->is_valid) {
            //check if user exists, if not, add this user
                   $user_id = get_profile( 'ID', $anonUserName );
                  $user_id = wp_create_user($anonUserName, wp_generate_password(20, false), '' );

             $my_post = array(
                   'post_title' => $_POST['Title'],
                   'post_content' => $_POST['Message'],
                   'post_status' => $my_post_type,
                   'post_author' => $user_id,
                   'post_category' => $category,
             //this thing enables normal comments only when comments are open and using Anon Comment is turned off
                   'comment_status' => (($enableComments && !$use_anonComment)  ? 'open' : 'closed'),
                   'ping_status' => 'closed'
            // Insert the post into the database
            $post_id = wp_insert_post( $my_post );
            if($post_id === 0){
                  $to_return .= 'error adding post';
                  //add meta tag, so AnonComment could add its comment field
                        add_post_meta($post_id, 'AnonComment', 'true', true);
                  //display new post link
                  //mod_rewrite will work with normal url's, like ?p=123
                  $urlArray = explode('?', $_SERVER['REQUEST_URI']);
                  $url = $urlArray[0];
                  $to_return .= 'post sucessfully added to database, post page: <a href='.$url.'?p='.$post_id.'>is here</a>';
            //error validating captcha
            $error = $resp->error;
            $to_return .= $error;
            $to_return .= 'reCAPTCHA validation failed, try again';
            $to_return .= displayFormStart($_POST['Title'], $_POST['Message']);
            $to_return .= recaptcha_get_html($publickey);
            $to_return .= displayFormEnd();
      return $to_return;

function displayFormStart($title = '', $message = ''){
      $form =<<< FORMSTART
<form action="{$_SERVER['REQUEST_URI']}" method="post">
Post title:<br><input type="text" name="Title" value="{$title}" size="40" maxlength="200"><br>
Your message:<br><textarea name="Message" cols=50 rows=20>{$message}</textarea><br>
      return $form;

function displayFormEnd(){
      $form_end =<<< FORMEND
<input type="submit" name="submit" value="Submit">
      return $form_end;

function add_css(){
      $css =<<< CSS
      <style type="text/css">
      form {
            align: center;
      textarea {
            background-color: white;
            color: black;
            align: center;
      return $css;

add_action('the_content', 'addAnonContent');
Ray PaseurCommented:
Here is the response page.  It looks like the programmer put in something like die('Could not open socket');
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="" dir="ltr" lang="en-US">
<head profile="">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

Overheard in Dublin -   Post a story</title>

<link rel="stylesheet" href="" type="text/css" media="screen" />

<style type='text/css' media='screen'>body {
	font-family: Verdana, Arial, Times New Roman, sans-serif;
	font-size: 75%;

h1, h2, h3, h4, h5, h6 {
   font-family: Lucida Grande, Verdana, Tahoma, Trebuchet MS!important;

#rotateimg { height: 200px!important; }</style>

<!--[if !IE]>deleted this if you want the indexing for archives<![endif]-->

<link rel="alternate" type="application/rss+xml" title="Overheard in Dublin RSS Feed" href="" />
<link rel="pingback" href="" />

<link rel="alternate" type="application/rss+xml" title="Overheard in Dublin &raquo; Post a story Comments Feed" href="" />
<link rel='stylesheet' id='A2A_SHARE_SAVE-css'  href='' type='text/css' media='all' />
<link rel='stylesheet' id='wdfb_style-css'  href='' type='text/css' media='all' />
<script type='text/javascript' src=''></script>
<script type='text/javascript' src=''></script>
<script type='text/javascript' src=''></script>
<script type='text/javascript' src=''></script>
<link rel="EditURI" type="application/rsd+xml" title="RSD" href="" />
<link rel="wlwmanifest" type="application/wlwmanifest+xml" href="" /> 
<link rel='index' title='Overheard in Dublin' href='' />
<link rel='canonical' href='' />

<script type="text/javascript"><!--
var a2a_config=a2a_config||{},wpa2a={done:false,html_done:false,script_ready:false,script_load:function(){var a=document.createElement('script'),s=document.getElementsByTagName('script')[0];a.type='text/javascript';a.async=true;a.src='';s.parentNode.insertBefore(a,s);wpa2a.script_load=function(){};},script_onready:function(){if(a2a.type=='page'){wpa2a.script_ready=true;if(wpa2a.html_done)wpa2a.init();}},init:function(){for(var i=0,el,target,targets=wpa2a.targets,length=targets.length;i<length;i++){el=document.getElementById('wpa2a_'+(i+1));target=targets[i];a2a_config.linkname=target.title;a2a_config.linkurl=target.url;if(el)a2a.init('page',{target:el});wpa2a.done=true;}}};a2a_config.tracking_callback=['ready',wpa2a.script_onready];
<script type="text/javascript">var _wdfb_ajaxurl="";</script><script type="text/javascript">var _wdfb_root_url="";</script>Could not open socket

Open in new window

Here is what I would do.  Since this site appears to be built on a WordPress platform, it is probably 100% PHP.  I would get a code scanner like Textpad "find in files" functionality and scan all of the scripts for the case-sensitive string Could not open socket and with each script that contains that string, I would look for conditional code - something testing a return value, perhaps from the fsockopen() function.  I am slightly suspicious of the reCaptcha implementation, but that's just an instinctive reaction.  Once you find the string in the script or scripts, we can dig a little deeper since we will be able to see the code that is in play.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ray PaseurCommented:
Ahh - just saw your post, I'll take a look at that now.
Ray PaseurCommented:
Here is an additional symptom to consider while you're looking for the string "Could not open socket."  If you do not put anything into the reCaptcha box,  the site says that Captcha validation failed.  If you put something in, right or wrong, the site says "Could not open socket."
Cosmic_CakeAuthor Commented:
" I am slightly suspicious of the reCaptcha implementation" - I agree

I think it also slows down user input.

Thanks for your suggestion, I will use Textpad and do a scan. Let's see if anything comes up.
Ray PaseurCommented:
10-4.  Post back here with the script that contains the culprit.  And if you want something that is effective but more client-friendly than reCaptcha see this article.

Best, ~Ray
Cosmic_CakeAuthor Commented:
I found it. It's in a files called recaptchalib.php.

Below is a segment. For the moment I would like to remove the captcha option on the website as all posts are monitored and hen put live, so no damage would be done.

 * Submits an HTTP POST to a reCAPTCHA server
 * @param string $host
 * @param string $path
 * @param array $data
 * @param int port
 * @return array response
function _recaptcha_http_post($host, $path, $data, $port = 80) {

        $req = _recaptcha_qsencode ($data);

        $http_request  = "POST $path HTTP/1.0\r\n";
        $http_request .= "Host: $host\r\n";
        $http_request .= "Content-Type: application/x-www-form-urlencoded;\r\n";
        $http_request .= "Content-Length: " . strlen($req) . "\r\n";
        $http_request .= "User-Agent: reCAPTCHA/PHP\r\n";
        $http_request .= "\r\n";
        $http_request .= $req;

        $response = '';
        if( false == ( $fs = @fsockopen($host, $port, $errno, $errstr, 10) ) ) {
                die ('Could not open socket');

        fwrite($fs, $http_request);

        while ( !feof($fs) )
                $response .= fgets($fs, 1160); // One TCP-IP packet
        $response = explode("\r\n\r\n", $response, 2);

        return $response;
Cosmic_CakeAuthor Commented:
I finally got rid of the horrible CAPTCHA and the posting is working now.

I changed true to false

$captchaEnabled = false; // enable reCAPTCHA (set to: true/false), do not use ' or "
Cosmic_CakeAuthor Commented:
Very practical answers, thank you.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
MySQL Server

From novice to tech pro — start learning today.