如何解决Laravel 5中的超时错误

我有以下设置:

在路线中,我有:

路线:: get(’articles’,’ArticlesController @ index’);

控制器中的index方法很简单:

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();

这样我才能真正显示最新的文章。我得到了错误:

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

…等等

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

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

回答:

的 错误与Laravel无关,而是与您的PHP配置有关。

这是解决方法。您需要更改的设置是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_time300秒更改为max_execution_time = 300

您可以phpinfo在本Loaded Configuration File节的函数输出中找到PHP配置文件的路径。

以上是 如何解决Laravel 5中的超时错误 的全部内容, 来源链接: utcz.com/qa/434277.html

回到顶部