Could not open socket

8,929 views
Skip to first unread message

braunbaer

unread,
May 30, 2007, 2:03:37 AM5/30/07
to reCAPTCHA
Hi,
I am testing reCAPTCHA on my Website: www.blankedv.at/check
After continue i see a message: "could not open socket".
Please help.
thanks
Gebhard

reCAPTCHA Support

unread,
May 30, 2007, 2:43:07 AM5/30/07
to reca...@googlegroups.com
Could you please post the code you are using? Otherwise, it won't be possible to debug
--
reCAPTCHA: stop spam, read books
http://recaptcha.net

braunbaer

unread,
May 31, 2007, 3:06:20 AM5/31/07
to reCAPTCHA
Hi,
I use the sample as it is:

<html>
<body>
<form action="" method="post">
<?php

require_once('recaptchalib.php');

// Get a key from http://recaptcha.net/api/getkey
$publickey = "...my publickey...";
$privatekey = "...my privatekey...";

# the response from reCAPTCHA
$resp = null;
# the error code from reCAPTCHA, if any
$error = null;

# was there a reCAPTCHA response?
if ($_POST["recaptcha_response_field"]) {
$resp = recaptcha_check_answer ($privatekey,
$_SERVER["REMOTE_ADDR"],

$_POST["recaptcha_challenge_field"],

$_POST["recaptcha_response_field"]);

if ($resp->is_valid) {
echo "You got it!";
} else {
# set the error code so that we can display it
$error = $resp->error;
}
}
echo recaptcha_get_html($publickey, $error);
?>
<br>
<input type="submit" value="submit" />
</form>
</body>
</html>


On 30 Mai, 08:43, "reCAPTCHA Support" <supp...@recaptcha.net> wrote:
> Could you please post the code you are using? Otherwise, it won't be
> possible to debug
>

Pietro

unread,
Jun 2, 2007, 4:29:56 PM6/2/07
to reCAPTCHA

I have just encountered this problem too. I think its our DNS. Try
replacing

$recaptcha_verify_server = 'api-verify.recaptcha.net';
with
$recaptcha_verify_server = '128.2.186.116';

in recaptchalib.php. It works for me.

Note that the first time I did this my public private keys seemed to
become invalid ... I know its a stupid thing to say, but that is
literally the only change I made on my whole machine and the keys were
no longer accepted and I had to generate new ones. I find that very
disconcerting.

Let me know if you figure out how to get the name resolution working.

reCAPTCHA Support

unread,
Jun 2, 2007, 5:20:18 PM6/2/07
to reca...@googlegroups.com
Hello,

On 6/2/07, Pietro <piet...@gmail.com> wrote:
On May 30, 7:03 am, braunbaer <gebh...@blankedv.at> wrote:
> Hi,
> I am testing reCAPTCHA on my Website:www.blankedv.at/check
> After continue i see a message: "could not open socket".
> Please help.
> thanks
> Gebhard

I have just encountered this problem too. I think its our DNS. Try
replacing

$recaptcha_verify_server = 'api-verify.recaptcha.net';
with
$recaptcha_verify_server = '128.2.186.116';

This solution has the potential to break. reCAPTCHA runs in multiple data centers so that we can have 100% uptime. A critical part of this is that we change DNS when a data center goes down (or in advance when there is scheduled downtime). Doing this change is at your own risk.

Can you run:

host api-verify.recaptcha.net

from your server? Also try running

dig +trace api-verify.recaptcha.net

in recaptchalib.php. It works for me.

Note that the first time I did this my public private keys seemed to
become invalid ... I know its a stupid thing to say, but that is
literally the only change I made on my whole machine and the keys were
no longer accepted and I had to generate new ones. I find that very
disconcerting.

Invalid how? What error message did you get?

Most likely, you accessed the website via a different host (eg, registered a key for localhost, used localhost for testing, then tried foo.bar.com). Keep in mind that keys are tied to hosts (as validated via the referrer header). Doing this enhances security.

Pietro

unread,
Jun 3, 2007, 3:10:05 AM6/3/07
to reCAPTCHA

On Jun 2, 10:20 pm, "reCAPTCHA Support" <supp...@recaptcha.net> wrote:
> Hello,


>
> On 6/2/07, Pietro <pietro...@gmail.com> wrote:
>
> > On May 30, 7:03 am, braunbaer <gebh...@blankedv.at> wrote:
> > > Hi,
> > > I am testing reCAPTCHA on my Website:www.blankedv.at/check
> > > After continue i see a message: "could not open socket".
> > > Please help.
> > > thanks
> > > Gebhard
>
> > I have just encountered this problem too. I think its our DNS. Try
> > replacing
>
> > $recaptcha_verify_server = 'api-verify.recaptcha.net';
> > with
> > $recaptcha_verify_server = '128.2.186.116';
>
> This solution has the potential to break. reCAPTCHA runs in multiple data
> centers so that we can have 100% uptime. A critical part of this is that we
> change DNS when a data center goes down (or in advance when there is
> scheduled downtime). Doing this change is at your own risk.
>

Hi.

Yeah, I figured it wasnt safe. Its just a temporary solution until I
figure out the real problem.


> Can you run:
>
> host api-verify.recaptcha.net
>
> from your server? Also try running
>
> dig +trace api-verify.recaptcha.net
>
> in recaptchalib.php. It works for me.
>

Is hostx the same thing?

# hostx api-verify.recaptcha.net
api-verify.recaptcha.net A 128.2.186.116
api-verify.recaptcha.net A 128.2.186.116
api-verify.recaptcha.net A 128.2.186.116
api-verify.recaptcha.net A 128.2.186.116
api-verify.recaptcha.net A 128.2.186.116

Im sorry but I dont understand where you want me to run that dig
command from ... I dont have a "dig" installed and dont know what
package it might be in ...


>
> > Note that the first time I did this my public private keys seemed to
> > become invalid ... I know its a stupid thing to say, but that is
> > literally the only change I made on my whole machine and the keys were
> > no longer accepted and I had to generate new ones. I find that very
> > disconcerting.
>
> Invalid how? What error message did you get?

My keys have stopped working again this morning. I am developing a
site locally. I have a virtual site under Apache and an entry in my
hosts file which directs my phony URL to localhost. When I tried using
keys generated with "localhost" they didnt work so I have used
"127.0.0.1". The error message I am seeing this morning is:

reCAPTCHA: Domain not authorized for key. [help]

Presumably if I generate new keys for 127.0.0.1 they will work (it did
last night). As I said, this was working fine when I shutdown last
night. The only thing I can think of is that my broadband connections
IP keeps changing, but I really dont think thats likely.


> Most likely, you accessed the website via a different host (eg, registered a
> key for localhost, used localhost for testing, then tried foo.bar.com). Keep
> in mind that keys are tied to hosts (as validated via the referrer header).
> Doing this enhances security.
>
> --
> reCAPTCHA: stop spam, read bookshttp://recaptcha.net

Its good that you provide this level of support. Thanks.

Pietro

unread,
Jun 3, 2007, 3:10:28 AM6/3/07
to reCAPTCHA

On Jun 2, 10:20 pm, "reCAPTCHA Support" <supp...@recaptcha.net> wrote:
> Hello,
>

> On 6/2/07, Pietro <pietro...@gmail.com> wrote:
>
> > On May 30, 7:03 am, braunbaer <gebh...@blankedv.at> wrote:
> > > Hi,
> > > I am testing reCAPTCHA on my Website:www.blankedv.at/check
> > > After continue i see a message: "could not open socket".
> > > Please help.
> > > thanks
> > > Gebhard
>
> > I have just encountered this problem too. I think its our DNS. Try
> > replacing
>
> > $recaptcha_verify_server = 'api-verify.recaptcha.net';
> > with
> > $recaptcha_verify_server = '128.2.186.116';
>
> This solution has the potential to break. reCAPTCHA runs in multiple data
> centers so that we can have 100% uptime. A critical part of this is that we
> change DNS when a data center goes down (or in advance when there is
> scheduled downtime). Doing this change is at your own risk.
>

Hi.

Yeah, I figured it wasnt safe. Its just a temporary solution until I
figure out the real problem.

> Can you run:
>
> host api-verify.recaptcha.net
>
> from your server? Also try running
>
> dig +trace api-verify.recaptcha.net
>
> in recaptchalib.php. It works for me.
>

Is hostx the same thing?

Im sorry but I dont understand where you want me to run that dig
command from ... I dont have a "dig" installed and dont know what
package it might be in ...


>


> > Note that the first time I did this my public private keys seemed to
> > become invalid ... I know its a stupid thing to say, but that is
> > literally the only change I made on my whole machine and the keys were
> > no longer accepted and I had to generate new ones. I find that very
> > disconcerting.
>
> Invalid how? What error message did you get?

My keys have stopped working again this morning. I am developing a


site locally. I have a virtual site under Apache and an entry in my
hosts file which directs my phony URL to localhost. When I tried using
keys generated with "localhost" they didnt work so I have used
"127.0.0.1". The error message I am seeing this morning is:

reCAPTCHA: Domain not authorized for key. [help]

Presumably if I generate new keys for 127.0.0.1 they will work (it did
last night). As I said, this was working fine when I shutdown last
night. The only thing I can think of is that my broadband connections
IP keeps changing, but I really dont think thats likely.

> Most likely, you accessed the website via a different host (eg, registered a
> key for localhost, used localhost for testing, then tried foo.bar.com). Keep
> in mind that keys are tied to hosts (as validated via the referrer header).
> Doing this enhances security.
>
> --

Pietro

unread,
Jun 3, 2007, 10:31:26 AM6/3/07
to reCAPTCHA
A thought: A record of the keys and corresponding domains is kept on
the server-side, yes? Well is it possible that I generated keys for
"127.0.0.1" and everything worked until someone else came along and
generated keys for their own "127.0.0.1", updating things on the
server, making my keys useless? i.e. Only 1 person can use 127.0.0.1
with reCAPTCHA at any time.

?

reCAPTCHA Support

unread,
Jun 3, 2007, 11:58:58 AM6/3/07
to reca...@googlegroups.com
No, that's not the case.

Just fyi the keys for localhost won't work for 127.0.0.1.

Dai

unread,
Jun 6, 2007, 11:36:53 PM6/6/07
to reCAPTCHA
Same issue. However I edited the $response in the recaptchalib.php
$response = '';
/* if( false == ( $fs = @fsockopen($host, $port, $errno, $errstr,
10) ) ) {
die ('Could not open socket');
}
*/

$fs = fsockopen($host, $port, $errno, $errstr, 30);
stream_set_blocking($fs, 0);
if (!$fs) {
die( "Now using blocking: $errstr ($errno)<br />\n");
}

I get back


Warning: fsockopen() [function.fsockopen]: unable to connect to api-
verify.recaptcha.net:80

Warning: stream_set_blocking(): supplied argument is not a valid
stream resource
Now using blocking: Host is down (64)

hope this helps find an answer.

reCAPTCHA Support

unread,
Jun 7, 2007, 12:06:36 AM6/7/07
to reca...@googlegroups.com
Just an idea: are you using some RedHat based system where selinux is taking affect? Do you have some sort of firewall?

Dai

unread,
Jun 7, 2007, 12:59:15 AM6/7/07
to reCAPTCHA
Thank you for your quick response. I have a home server running os x
server. I have disabled firewalls and the issue persists. I can ping
api-verify.recaptcha.net, visit api-verify.recaptcha.net in a browser
and dig api-verify.recaptcha.net from all machines on my network.

-D


On Jun 7, 12:06 am, "reCAPTCHA Support" <supp...@recaptcha.net> wrote:
> Just an idea: are you using some RedHat based system where selinux is taking
> affect? Do you have some sort of firewall?
>

> On 6/6/07, Dai <dai.sweng...@gmail.com> wrote:
>
>
>
>
>
> > Same issue. However I edited the $response in the recaptchalib.php
> > $response = '';
> > /* if( false == ( $fs = @fsockopen($host, $port, $errno, $errstr,
> > 10) ) ) {
> > die ('Could not open socket');
> > }
> > */
>
> > $fs = fsockopen($host, $port, $errno, $errstr, 30);
> > stream_set_blocking($fs, 0);
> > if (!$fs) {
> > die( "Now using blocking: $errstr ($errno)<br />\n");
> > }
>
> > I get back
>
> > Warning: fsockopen() [function.fsockopen]: unable to connect to api-
> > verify.recaptcha.net:80
>
> > Warning: stream_set_blocking(): supplied argument is not a valid
> > stream resource
> > Now using blocking: Host is down (64)
>
> > hope this helps find an answer.
>

reCAPTCHA Support

unread,
Jun 7, 2007, 1:08:08 AM6/7/07
to reca...@googlegroups.com
Can you contact any other server using PHP?

On 6/6/07, Dai <dai.sw...@gmail.com> wrote:

mariuss

unread,
Jul 2, 2007, 10:08:01 PM7/2/07
to reCAPTCHA
Had the same issue. Regenerated the keys for the site and now it
works.

proteus

unread,
Jul 24, 2007, 7:44:38 PM7/24/07
to reCAPTCHA
Just in case someone else stumbles across a similar problem, note that
you will get the same error if globals are disabled on your server.

I had the same problem just now. The quickest solution is to replace
the use of globals ($recaptcha_api_server,
$recaptcha_api_secure_server and $recaptcha_verify_server) with
constants.

Ooze

unread,
Jul 26, 2007, 10:49:23 PM7/26/07
to reCAPTCHA
YOOOOOOOW.....

so, what's the solution for this "Socket" problem???

I dunno why, but if I activate the reCAPTCHA on my blog (I'm using
wordpress), then I can't receive any comments....
It will come to "Could not open socket"

So, for now I just deactivate this reCAPTCHA so that I can receive the
comments, but then again there are many "tramadols" (SPAM) come to my
blog.. (>_<)

Anyone can help?

reCAPTCHA Support

unread,
Jul 26, 2007, 10:51:14 PM7/26/07
to reca...@googlegroups.com

Ooze

unread,
Jul 26, 2007, 11:13:41 PM7/26/07
to reCAPTCHA
Thx for the fast answer (^_^)
but.... Umm...
sorry...
I still don't get it (^_^)

so, what should I replace (write) on recaptchalib.php ?

I just change the word "global" with "constants" ???

** sorry I'm a beginner in this kind of thing (^_^) **


On Jul 27, 9:51 am, "reCAPTCHA Support" <supp...@recaptcha.net> wrote:
> One person said:
>
> The quickest solution is to replace
>
> > the use of globals ($recaptcha_api_server,
> > $recaptcha_api_secure_server and $recaptcha_verify_server) with
> > constants.
>

> On 7/26/07, Ooze <ivan.kurnia...@gmail.com> wrote:
>
>
>
>
>
>
>
> > YOOOOOOOW.....
>
> > so, what's the solution for this "Socket" problem???
>
> > I dunno why, but if I activate the reCAPTCHA on my blog (I'm using
> > wordpress), then I can't receive any comments....
> > It will come to "Could not open socket"
>
> > So, for now I just deactivate this reCAPTCHA so that I can receive the
> > comments, but then again there are many "tramadols" (SPAM) come to my
> > blog.. (>_<)
>
> > Anyone can help?
>
> > On Jul 25, 6:44 am, proteus <sebastian.avarva...@gmail.com> wrote:
> > > Just in case someone else stumbles across a similar problem, note that
> > > you will get the same error if globals are disabled on your server.
>
> > > I had the same problem just now. The quickest solution is to replace
> > > the use of globals ($recaptcha_api_server,
> > > $recaptcha_api_secure_server and $recaptcha_verify_server) with
> > > constants.
>
> --

> reCAPTCHA: stop spam, read bookshttp://recaptcha.net- Hide quoted text -
>
> - Show quoted text -

reCAPTCHA Support

unread,
Jul 27, 2007, 1:44:41 AM7/27/07
to reca...@googlegroups.com
Try what this poster suggests:



I encountered a problem with the recaptchalib.php when trying to
install it on my website running on a php 5 configuration. It appears
that the problem came from the global variables. No idea, if it comes
from my specific configuration but anyway. I replaced the global
coinfig variables by constants which make the script run without any
problems since that. I think it could be better to do such a
replacement on the 'official' script. What do you think about it ?

My modifications are below :

// at the beginning of the file, suppress vars
//and define constants
define('RECAPTCHA_API_SERVER',
' http://api.recaptcha.net');
define('RECAPTCHA_API_SECURE_SERVER','https://api-
secure.recaptcha.net');
define('RECAPTCHA_VERIFY_SERVER','api-verify.recaptcha.net ');

//suppress "global" declarations

//replace
          $recaptcha_api_server
// by the constant
          RECAPTCHA_API_SERVER

Hope this helps

On 7/26/07, Ooze <ivan.ku...@gmail.com> wrote:

Andy Armstrong

unread,
Jul 27, 2007, 3:46:33 AM7/27/07
to reca...@googlegroups.com
On 27 Jul 2007, at 06:44, reCAPTCHA Support wrote:
> I encountered a problem with the recaptchalib.php when trying to
> install it on my website running on a php 5 configuration. It appears
> that the problem came from the global variables. No idea, if it comes
> from my specific configuration but anyway. I replaced the global
> coinfig variables by constants which make the script run without any
> problems since that. I think it could be better to do such a
> replacement on the 'official' script. What do you think about it ?

Is it possible that you were calling recaptchalib inside a function
and that therefore the globals weren't visible?

--
Andy Armstrong, hexten.net

Wahab Hussain

unread,
Feb 15, 2012, 4:29:55 AM2/15/12
to reca...@googlegroups.com

Mansoorkhan T K

unread,
Mar 12, 2013, 3:52:37 AM3/12/13
to reca...@googlegroups.com
hi,
My reCAPTCHA is working fine in my testing server, when it goes live, it is not working. I'm using global keys. 
Error is "could not open socket."


Reply all
Reply to author
Forward
0 new messages