在 PHP 脚本中获取 max_execution_time
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8562398/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Get max_execution_time in PHP script
提问by T Zengerink
I know it is possible to set the maximum execution time in a script using either:
我知道可以使用以下任一方法在脚本中设置最大执行时间:
ini_set('max_execution_time', 30);
or
或者
set_time_limit(30);
What can I do to get a variable containing the maximum execution time in seconds?
我该怎么做才能获得包含最大执行时间(以秒为单位)的变量?
回答by Jon
The converse, using ini_get:
相反,使用ini_get:
ini_get('max_execution_time');
Note: if you check the documentation page for ini_set, you can find ini_getlisted prominently on the "See Also" section. That's a very good way to discover functionality built into PHP that you are not already aware of.
注意:如果您查看 的文档页面ini_set,您会发现ini_get在“另请参阅”部分的显着位置列出。这是发现 PHP 内置功能的一种非常好的方式,您还没有意识到。
回答by David
There are some inaccurate points in the comments. So to clarify:
评论中有一些不准确的地方。所以要澄清:
set_time_limit(30)is the same asini_set('max_execution_time', 30);- Both of them reset the counter.
ini_get('max_execution_time')works for both cases -set_time_limitandini_set.
set_time_limit(30)是相同的ini_set('max_execution_time', 30);- 他们都重置了计数器。
ini_get('max_execution_time')适用于两种情况 -set_time_limit和ini_set.
回答by Shades88
you can try
你可以试试
$max_time = ini_get("max_execution_time");
echo $max_time;
and you can use this variable the way you want to :)
你可以按照你想要的方式使用这个变量:)
回答by haynar
try this:
尝试这个:
ini_get('max_execution_time')

