睡眠睡眠功能延迟? [英] Php sleep function for delay?

查看:99
本文介绍了睡眠睡眠功能延迟?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设一个网站的访问量很高,我想使用php sleep(4)函数来避免泛滥。是个好主意还是我应该使用其他延迟方式? sleep()使连接保持打开状态,这可能是一个问题吗?

Suppose a website with 'high' traffic, I want to use the php sleep(4) function to avoid flooding. Is it a good idea or should I use different delay ways ? sleep() keeps a connection open, could this be a problem ?

我这样做:

index.php -> stuff.php -> index.php

Stuff.php做点什么然后睡觉(4);因此,用户等待黑屏4秒钟,然后返回索引。谢谢。

Stuff.php does something and then sleep(4); so the user waits 4 seconds with a blank screen, and then goes back to index. Thanks.

更新:我的敌人都是黑客,他们想要DOS,并且压力很大,他们会快速点击搜索按钮,说...这就是为什么我要使用服务器端延迟。<​​/ p>

Update: My enemies are both, hackers, that wants a DOS, and stressed pepole that click fast on the search button, lets say... Thats why I would use a server-side delay.

推荐答案

这不是一个好方法,因为即使做'sleep apache / php仍然占用该连接的OS进程。因此,在人流量大的网站上,您将获得大量同时运行的Apache进程,这些进程将占用服务器的所有RAM。

It is not good approach because even doing 'sleep' apache/php still occupies OS process for that connection. So, on website with high traffic you will get lots of simultaneously running Apache processes that will eat all your server's RAM.

相反,您可以修改其中一个页面并放入一些Javascript代码,因此它可能要等待几秒钟,然后使用JavaScript导航到下一页。那应该可以解决您的问题。

Instead, You can modify one of your pages and put some Javascript code to it, so it could wait for few seconds, and then navigate to the next page by javascript. That should solve your problem.

这篇关于睡眠睡眠功能延迟?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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