PHP:检测并显示"服务器超载"信息 [英] PHP: Detect and show "Server overloaded" message

查看:181
本文介绍了PHP:检测并显示"服务器超载"信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经注意到了一些网站,如 hypem.com 显示你没有得到服务的错误消息时,现场忙而不只是让人们等待,超时或刷新;加重恐怕是一个服务器负载问题。

I have noticed a few websites such as hypem.com show a "You didnt get served" error message when the site is busy rather than just letting people wait, time out or refresh; aggravating what is probably a server load issue.

我们太加载到处理您的请求。请点击返回你的
  浏览器并尝试你再次做什么。

We are too loaded to process your request. Please click "back" in your browser and try what you were doing again.

这是如何实现之前,服务器过载?这听起来像一个真正整洁的方式来管理用户的期望,如果一个网站发生超载,同时也给现场的时间来恢复。

How is this achieved before the server becomes overloaded? It sounds like a really neat way to manage user expectation if a site happens to get overloaded whilst also giving the site time to recover.

推荐答案

另一个选项是这样的:

$load = sys_getloadavg();
if ($load[0] > 80) {
    header('HTTP/1.1 503 Too busy, try again later');
    die('Server too busy. Please try again later.');
}

我是从PHP的网站 http://php.net/sys_getloadavg ,altough我不知道什么样的价值观重新present的sys_getloadavg返回

I got it from php's site http://php.net/sys_getloadavg, altough I'm not sure what the values represent that the sys_getloadavg returns

这篇关于PHP:检测并显示"服务器超载"信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆