fsockopen() 无法在特定网络主机上运行?

发布于 2024-12-14 19:23:37 字数 1218 浏览 5 评论 0原文

我们的一位客户说他们有一个非常简单的脚本,它使用 fsockopen() 来确定服务器是否在线。他们说直到最近它通过我们在他们的网站上运行良好,但最近刚刚停止工作,所以我假设这是一个设置。

我的第一个想法是他将其用作 TCP 并使用 IP/端口作为游戏服务器,但是他和我都确认该脚本在其他各种网络主机上运行良好。

我们的问题可能是什么?

工作: http://crazygfl.xfactorservers.com/query .php?ip=www.xfactorservers.com&port=80

工作:http://crazygfl-stats.com/query.php?ip= 109.73.163.231&port=27015

不起作用:http://crazygfl.xfactorservers.com/query.php?ip= 109.73.163.231&port=27015

这是代码...

<?php

    $timeout = (isset($_GET['timeout']) ? ($_GET['timeout'] <= 0 ? 30 : ((int)$_GET['timeout'])) : 30);

    if(empty($_GET['ip'])&&empty($_GET['port'])){
        echo 'No IP/Port specified.';
    }else{
        if(fsockopen($_GET['ip'], $_GET['port'], $errno, $errstr, $timeout) === false){
            echo 'offline';
        }else{
            echo 'online';
        }
    }

One of our customers said they have a very simple script which uses fsockopen() to determine whether a server is online or not. They said until recently it worked fine on their website through us, but recently just stopped working, so I am assuming it is a setting.

My first thought was that he was using it as TCP and using the IP/Port for a Game Server, however he and myself both confirmed the script worked fine from various other web hosts.

What could be the issue on ours in particular?

Works: http://crazygfl.xfactorservers.com/query.php?ip=www.xfactorservers.com&port=80

Works: http://crazygfl-stats.com/query.php?ip=109.73.163.231&port=27015

Doesn't Work: http://crazygfl.xfactorservers.com/query.php?ip=109.73.163.231&port=27015

Here is the code...

<?php

    $timeout = (isset($_GET['timeout']) ? ($_GET['timeout'] <= 0 ? 30 : ((int)$_GET['timeout'])) : 30);

    if(empty($_GET['ip'])&&empty($_GET['port'])){
        echo 'No IP/Port specified.';
    }else{
        if(fsockopen($_GET['ip'], $_GET['port'], $errno, $errstr, $timeout) === false){
            echo 'offline';
        }else{
            echo 'online';
        }
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

流年里的时光 2024-12-21 19:23:37

托管公司可能已禁用 fsockopen 功能或在您尝试测试的任何端口上对出站请求进行防火墙处理。如果是这种情况,您可以要求他们重新启用该功能或​​解锁端口,但如果他们不这样做,那么除了转移到新主机之外,您几乎没有什么办法。

顺便说一句,直接使用来自用户输入的数据($_GET、$_POST 等)而不进行任何类型的验证是一个非常糟糕的主意!

It's possible that the hosting company have disabled the fsockopen function or firewalled outbound requests on whatever port you're trying to test. If that's the case you can ask them to reenable the function or unblock the port, but if they won't then you have very little recourse other than moving to a new host.

BTW, using data directly from user input ($_GET, $_POST, etc) without any kind of validation is an EXTREMELY bad idea!

挽你眉间 2024-12-21 19:23:37

您上面引用的三台主机是在同一台机器上,还是在不同的机器上?可能是它们之间的配置不一致。检查“fsockopen”是否启用:

 <?php
 if(function_exists('fsockopen')) {
      echo "fsockopen function is enabled";
 }
 else {
      echo "fsockopen is not enabled";
 }
 ?>

如果启用,请检查防火墙规则是否阻止未成功的主机。

如果失败,请将脚本迁移到基于 cURL 的实现: http://ch.php.net/curl看看这是否有助于解决问题。

Are the three hosts you quoted above all on the same machine, or are they on separate machines? It could be that the configurations between them are not consistent. Check to see if 'fsockopen' is enabled:

 <?php
 if(function_exists('fsockopen')) {
      echo "fsockopen function is enabled";
 }
 else {
      echo "fsockopen is not enabled";
 }
 ?>

If it is enabled, check to see if firewall rules are blocking the host that is not successful.

Faililng that, migrate your script to a cURL based implementation: http://ch.php.net/curl and see if that helps to resolve the issue.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文