有效检查站点/服务器正常运行时间的最佳方法是什么(PHP)

发布于 2024-09-07 22:53:54 字数 205 浏览 2 评论 0原文

我正在尝试用 PHP 构建一个监控站点/服务器正常运行时间的系统,该系统将需要每分钟检查数千个域/ip。我研究过 cURL,因为这似乎是最好的方法。

编辑: 系统将需要探测服务器,检查其响应时间是否合理,并返回其响应代码。然后它将向 mysql 数据库添加一行,其中包含响应时间和状态代码。系统的通知部分从这里开始就相当简单了。该系统将位于专用服务器上。希望这能增加一些清晰度。

I am trying to build a system of monitoring site / server uptime in PHP, the system will be required to check thousands of domains / ips a minute. I have looked into cURL as this seems to be the best method.

Edit:
The system will be required to probe a server, check its response time is reasonable, and return its response code. It will then add a row to a mysql db containing response time and status code. The notification part of the system is fairly straight forward from there. The system will be on dedicated servers. Hope this adds some clarity.

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

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

发布评论

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

评论(4

丑丑阿 2024-09-14 22:53:54

为什么不采用 KISS 方法并使用 php 的 get_headers() 函数?

如果您想检索状态代码,请参阅 php 手册页注释中的片段:

function get_http_response_code($theURL) {
  $headers = get_headers($theURL);
  return substr($headers[0], 9, 3); 
}

此函数(作为核心 php 功能)应该比curl 更快、更高效。

Why not go for the KISS approach and use php's get_headers() function?

If you want to retrieve the status code, here's a snippet from the comments to the php manual page:

function get_http_response_code($theURL) {
  $headers = get_headers($theURL);
  return substr($headers[0], 9, 3); 
}

This function (being a core php feature) should be faster and more efficient than curl.

纵山崖 2024-09-14 22:53:54

如果我理解正确的话,你的这个系统将不断地连接到数千个域/ip,如果它有效,它就假设服务器已启动并正在运行?

我想您可以使用 cURL,但这会花费很长时间,特别是如果您正在谈论数千个请求 - 您需要多个服务器和大量带宽才能正常工作。

您还可以查看多线程请求的 multi cURL(即同时发出 10 个以上 cURL 请求,而不是一次一个)。

http://php.net/manual/en/function.curl-多重执行.php

If I understand correctly, this system of yours will constantly be connecting to thousands of domains/ips, and if it works, it assumes that the server is up and running?

I suppose you could use cURL, but it would take a long time especially if you're talking thousands of requests - you'd need multiple servers and lots of bandwidth for this to work properly.

You can also take a look at multi cURL for multi-threaded requests (ie. simultaneously sending out 10+ cURL requests, instead of one at a time).

http://php.net/manual/en/function.curl-multi-exec.php

明月松间行 2024-09-14 22:53:54

对于此类事情有非常好的工具。不需要自己写。

例如,看看 Nagios 。许多管理员使用它进行监控。

There are very good tools for things like that. No need to write it on your own.

Have a look at Nagios for example. Many admins use it for monitoring.

坏尐絯℡ 2024-09-14 22:53:54

您的瓶颈将在于等待给定主机响应。假设有 30 秒超时和 N 个主机要检查,并且除最后一个主机之外的所有主机都没有响应,则您需要等待 30(N-1) 秒才能检查最后一个主机。您可能永远无法检查最后一个主机。

您当然需要发送多个 HTTP 请求 - 要么是已经建议的 multi cURL,要么是 OO 方法的 HttpRequestPool 类。

您还需要考虑如何将 N 个主机的集合分解为最大数量的子集,以避免由于必须首先处理无响应主机队列而导致无法到达主机的问题。

从 1 台服务器检查 N 台主机最有可能由于无响应主机队列而无法到达一台或多台主机。这是最便宜、最简单且最不可靠的选择。

从 N 个服务器中各检查 1 台主机,由于无响应主机队列而无法到达一台或多台主机的可能性最小。这是最昂贵、(可能)最困难和最可靠的选择。

考虑最适合您的成本/难度/可靠性平衡。

Your bottleneck will be in waiting for a given host to respond. Given a 30 second timeout and N hosts to check and all but the last host not responding, you'll need to wait 30(N-1) seconds to check the last host. You may never get to checking the last host.

You certainly need to send multiple HTTP requests - either multi cURL as already suggested, or the HttpRequestPool class for an OO approach.

You will also need to consider how to break the set of N hosts to check down into a maximum number of subsets to avoid the problem of failing to reach the a host due to having to first deal with a queue of non-responding hosts.

Checking N hosts from 1 server presents the greatest chance of not reaching one or more hosts due to a queue of non-responding hosts. This is the cheapest, most easy and least reliable option.

Checking 1 host each from N servers presents the least chance of not reaching one not reaching one or more hosts due to a queue of non-responding hosts. This is the most expensive, (possibly) most difficult and most reliable option.

Consider a cost/difficulty/reliability balance that works best for you.

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