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条)

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度