duanfen1312 2014-01-12 13:52
浏览 81
已采纳

fsockopen返回服务器错误(0)

I'm checking fsockopen in Ubuntu server 13.04 with this code:

<?php 
  $fp = fsockopen("www.google.com", 80, $errno, $errstr, 30); 
  if (!$fp) { 
      echo "$errstr ($errno)<br />
"; 
  } else { 
      $out = "GET / HTTP/1.1
"; 
      $out .= "Host: www.example.com
"; 
      $out .= "Connection: Close

"; 

      fwrite($fp, $out); 
      while (!feof($fp)) { 
          echo fgets($fp, 128); 
      } 
      fclose($fp); 
  } 
?>

and the server returning

php_network_getaddresses: getaddrinfo failed: System error (0)

Any help with this?

  • 写回答

3条回答 默认 最新

  • duanduoding2238 2014-01-12 13:58
    关注

    There is no problem in your code - it's fine and working!

    Most probably the firewall is blocking 80 port and this is why you can't connect.

    Check your connection from the console and see what you get:

    ping google.com
    

    EDIT 1:

    Most likely you have a problem in your /etc/resolv.conf or /etc/hosts. To solve this you could refer to: Ping: Unknown host. If you can't just post output of those files and we'll see of what I could do!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥25 关于##爬虫##的问题,如何解决?:
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码
  • ¥50 随机森林与房贷信用风险模型
  • ¥50 buildozer打包kivy app失败
  • ¥30 在vs2022里运行python代码
  • ¥15 不同尺寸货物如何寻找合适的包装箱型谱
  • ¥15 求解 yolo算法问题
  • ¥15 虚拟机打包apk出现错误