如何解决Laravel 5中的超时错误 [英] How to solve a timeout error in Laravel 5

查看:505
本文介绍了如何解决Laravel 5中的超时错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我进行了以下设置:

在路线上,我有

Route :: get('articles','ArticlesController @ index');

Route::get('articles', 'ArticlesController@index');

控制器中的索引方法很简单:

The index method in the controller is simply:

public function index()
{
   $articles = Article::all();
   return View('articles.index', compact('articles'));
}

并在视图中:

@extends('../app')
@section('content')
<h1>Articles</h1>
<p>
    @foreach($articles as $article)
    <article>
        <h2><a href="{{action('ArticlesController@show', [$article->id])}}">{{$article->title}}</a></h2>
        <p>{{ $article->body }}</p>
    </article>
    @endforeach
</p>
@stop

我试图替换:

$articles = Article::all();

使用

$article = Article::latest()->get();

这样我实际上可以首先显示最新文章. 我得到了错误:

such that I can actually show the articles latest first. I got the error:

FatalErrorException in Str.php line 322:
Maximum execution time of 30 seconds exceeded

,调用堆栈为:

in Str.php line 322
at FatalErrorException->__construct() in HandleExceptions.php line 131
at HandleExceptions->fatalExceptionFromError() in HandleExceptions.php line 116
at HandleExceptions->handleShutdown() in HandleExceptions.php line 0
at Str::snake() in helpers.php line 561
at snake_case() in ControllerInspector.php line 105
at ControllerInspector->getVerb() in ControllerInspector.php line 78
at ControllerInspector->getMethodData() in ControllerInspector.php line 39
at ControllerInspector->getRoutable() in Router.php line 251
at Router->controller() in Router.php line 226
at Router->controllers() in Facade.php line 210
at Facade::__callStatic() in routes.php line 21
at Route::controllers() in routes.php line 21
in RouteServiceProvider.php line 40

...等等

我已经将控制器方法恢复到原来的状态,但是错误仍然存​​在.

I have restored the controller method to what it was, but the error persists.

您能告诉我如何解决这个问题吗?

Can you please tell me how I can solve this problem?

推荐答案

最长执行时间超过30秒错误与Laravel无关,而是与您的PHP配置有关.

The Maximum execution time of 30 seconds exceeded error is not related to Laravel but rather your PHP configuration.

这是解决问题的方法.您将需要更改的设置是max_execution_time.

Here is how you can fix it. The setting you will need to change is max_execution_time.

;;;;;;;;;;;;;;;;;;;
; Resource Limits ;
;;;;;;;;;;;;;;;;;;;

max_execution_time = 30     ; Maximum execution time of each script, in seconds
max_input_time = 60 ; Maximum amount of time each script may spend parsing request data
memory_limit = 8M      ; Maximum amount of memory a script may consume (8MB)

您可以将max_execution_time更改为300秒,如max_execution_time = 300

You can change the max_execution_time to 300 seconds like max_execution_time = 300

您可以在Loaded Configuration File部分的phpinfo函数的输出中找到PHP配置文件的路径.

You can find the path of your PHP configuration file in the output of the phpinfo function in the Loaded Configuration File section.

这篇关于如何解决Laravel 5中的超时错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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