ini_set('max_execution_time',0)是个坏主意吗? [英] Is ini_set('max_execution_time', 0) a bad idea?

查看:238
本文介绍了ini_set('max_execution_time',0)是个坏主意吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有充分的理由不设置PHP配置变量 max_execution_time 设为0?

Is there a good reason not to set the PHP configuration variable max_execution_time to 0?

同事最近签入了对添加的文件的更改:

A coworker recently checked in a change to a file that added:

ini_set('max_execution_time', 0);

对于在将输出返回给用户之前进行了一些复杂处理的页面,默认值太低了.

The default value had been too low for a page that did some complex processing before returning the output to the user.

手册指出该设置的主要目的是:

The manual states that the main purpose of the setting is to:

防止编写不正确的脚本占用服务器.

prevent poorly written scripts from tying up the server.

但也要声明:

您的Web服务器可以具有其他超时配置,这些配置也可能会中断PHP执行. Apache具有 Timeout 指令,而IIS具有CGI超时功能.两者默认为300秒.有关详细信息,请参见您的Web服务器文档.

Your web server can have other timeout configurations that may also interrupt PHP execution. Apache has a Timeout directive and IIS has a CGI timeout function. Both default to 300 seconds. See your web server documentation for specific details.

我们在Apache下运行,因此 Timeout 设置适用.是否有任何理由不将max_execution_time全局设置为零?我主要是想知道将该值设置为零时是否忽略了我的好处.

We're running under Apache, so that Timeout setting applies. Is there any reason not to set max_execution_time to zero globally? I'm mainly curious as to whether there are benefits I'm overlooking when not setting it to zero.

推荐答案

冒着激怒你的危险;

您问的是错误的问题.您不需要不背离默认值的理由,而是需要相反的理由.您需要这样做的理由.运行Web服务器时,超时是绝对必不可少的,即使无缘无故地禁用该设置,这也与良好做法背道而驰,即使该运行在恰好具有自己的超时指令的Web服务器上也是如此.

You're asking the wrong question. You don't need a reason NOT to deviate from the defaults, but the other way around. You need a reason to do so. Timeouts are absolutely essential when running a web server and to disable that setting without a reason is inherently contrary to good practice, even if it's running on a web server that happens to have a timeout directive of its own.

现在,关于真正的答案;在这种情况下,可能根本没有关系,但是通过单独的系统设置是不明智的做法.如果脚本以后以不同的超时在不同的服务器上运行怎么办?如果您可以肯定地说它永远不会发生,那很好,但是好的做法主要是考虑到看似不太可能发生的事件,而不是不必要地将完全不同的系统的设置和功能联系在一起.不遵守这些原则会导致软件领域出现许多毫无意义的不兼容性.几乎每次都无法预料.

Now, as for the real answer; probably it doesn't matter at all in this particular case, but it's bad practice to go by the setting of a separate system. What if the script is later run on a different server with a different timeout? If you can safely say that it will never happen, fine, but good practice is largely about accounting for seemingly unlikely events and not unnecessarily tying together the settings and functionality of completely different systems. The dismissal of such principles is responsible for a lot of pointless incompatibilities in the software world. Almost every time, they are unforeseen.

如果稍后将Web服务器设置为运行其他仅从Web服务器继承超时设置的运行时环境,该怎么办?举例来说,假设您后来需要一个由C ++编写的15年历史的CGI程序,该程序是由搬到另一个大陆的人编写的,除了Web服务器之外,它没有任何超时的想法.这可能会导致需要更改超时,并且由于PHP无意义地依赖于Web服务器的超时而不是其自身的超时,因此可能会导致PHP脚本出现问题.或相反,由于某种原因,您需要较少的Web服务器超时,但PHP仍需要提高超时时间.

What if the web server later is set to run some other runtime environment which only inherits the timeout setting from the web server? Let's say for instance that you later need a 15-year-old CGI program written in C++ by someone who moved to a different continent, that has no idea of any timeout except the web server's. That might result in the timeout needing to be changed and because PHP is pointlessly relying on the web server's timeout instead of its own, that may cause problems for the PHP script. Or the other way around, that you need a lesser web server timeout for some reason, but PHP still needs to have it higher.

将PHP功能绑定到Web服务器并不是一个好主意,因为Web服务器和PHP负责不同的角色,并且应在功能上保持尽可能的独立.当PHP方面需要更多处理时间时,应该将它作为PHP中的一项设置,仅仅是因为它与PHP相关,而不一定与Web服务器上的其他所有事物有关.

It's just not a good idea to tie the PHP functionality to the web server because the web server and PHP are responsible for different roles and should be kept as functionally separate as possible. When the PHP side needs more processing time, it should be a setting in PHP simply because it's relevant to PHP, not necessarily everything else on the web server.

简而言之,只是在不需要时将事情不必要地混为一谈.

In short, it's just unnecessarily conflating the matter when there is no need to.

最后但并非最不重要的一点是,静止"是正确的;您至少应该使用set_time_limit()而不是ini_set().

Last but not least, 'stillstanding' is right; you should at least rather use set_time_limit() than ini_set().

希望这不是太光顾和令人讨厌.就像我说的那样,在您的特定情况下可能很好,但是最好不要将您的情况视为唯一的真实情况.就这样. :)

Hope this wasn't too patronizing and irritating. Like I said, probably it's fine under your specific circumstances, but it's good practice to not assume your circumstances to be the One True Circumstance. That's all. :)

这篇关于ini_set('max_execution_time',0)是个坏主意吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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