在 symfony2 中为特定控制器设置 max_execution_time [英] Set max_execution_time for specific controller in symfony2
问题描述
使用ini_set()
,我可以扩展脚本的最大执行时间.在 Symfony2 中,我可以将 ini_set
添加到 web/app.php
和 web/app_dev.php
以应用增加了所有控制器的执行时间.
Using ini_set()
, I can expand the maximum execution time of a script. In Symfony2, I can add ini_set
to web/app.php
and web/app_dev.php
to apply the increased execution time to all controllers.
但在这种情况下,我只想为 Symfony2 中的一个特定控制器操作扩展最大执行时间.我宁愿不让其他操作有可能运行更长的时间.
But in this case, I only want to expand the maximum execution time for one specific controller action in Symfony2. I'd rather not give other actions the possibility to run for a longer time than necessary.
我尝试在控制器的动作函数顶部添加 ini_set
,但这似乎不起作用.任何解决方案?谢谢!
I tried adding the ini_set
at the top of the action function in the controller, but that doesn't seem to work. Any solutions? Thanks!
推荐答案
您可以使用 set_time_limit
函数禁用 PHP 超时限制.更多信息这里
You can disable the PHP timeout limit with the set_time_limit
function. More info here
例如:
class TaskController extends Controller
{
public function longTaskAction()
{
set_time_limit(0); // 0 = no limits
// ..
}
}
这篇关于在 symfony2 中为特定控制器设置 max_execution_time的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!