duanqinqian5299 2010-07-12 22:02
浏览 56
已采纳

“无法打开插座”

How do I alleviate the "Could not open socket" error that is happening on my site?

I have troubleshot that it is CAPTCHA (I'm using reCAPTCHA). It is only displaying this error on the two pages where I use reCAPTCHA.

I have been generating new sets of keys, and sometimes it works and sometimes it does not. For example, it worked on Safari and sometimes not, but on Firefox, and vice versa, and it worked for me and not for one of my partners and vice versa.

How can I fix this problem? Could it be that my server is having trouble doing the fsocketopen command? If so, how do I fix that?

  • 写回答

1条回答 默认 最新

  • doulin2555 2010-07-13 18:20
    关注

    Could it be that my server is having trouble doing the fsocketopen command?

    Exactly -- although it doesn't necessarily mean that something is wrong with your server. It just means that somewhere between your server and the recaptcha server, there's a network communications problem that prevents the socket connection from being opened.

    This could be a lot of things. It could be a config issue with your code or on your server, (particularly if there's some aspect of the configuration on your server that's dynamic), it could be an issue with the level of connectivity your server has, it could be a network config issue where your server is hosted, it could be a network configuration issue anywhere between your server and the recaptcha server, it could be a bandwidth issue where they're hosted, it could be a configuration issue on their side. You might want to use the extra error reporting arguments to fsockopen to see if you can get any messages that make sense. You might also try your setup out on at least 2-3 different servers on totally different networks -- that could also give you a somewhat specific indication about where the problem is.

    The other question, though, is how you're going to manage this kind of thing in general. fsockopen just sometimes fails to get a connection, because in even the best configured network environment, there's no communications guarantee. Hardware fails, accidents happen, network admins have fat-finger moments, remote servers get confused, global thermonuclear war can take out a data center -- you just never know. So you've got to write your code (and manage your setup) so you've got fallback cases for when failure happens and you display error messages that are acceptable for the end user.

    You might want to look into PHP's set_error_handler function and set up a function to be called on occurrences where fsockopen fails. In some situations, I've become fond of using it to trigger exceptions, something like this:

    function throw_error_exception($number = 0, $str = '',$file = null,$line = null) {
       throw new ErrorException($str, 0, $number, $file, $line);
    }
    
    set_error_handler('throw_error_exception',E_ALL);
    

    With that setup, you could manage fsockopen connections something like this:

    try {
       fsockopen('remote.host.com',8080,$fso_errnum,$fso_errstr,30);
    } catch(Exception $e) {
       // here you can look at properties/methods of $e, and $fso_* values, and 
       // figure out what nice error messages you want to display for your users
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器