I have the following set up:
In routes I have:
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')); }
and in the view:
@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
I attempted to replace the:
$articles = Article::all();
with
$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
and the call stack is:
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
... etc
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?
You can call set_time_limit(0) to remove the time limit from the rest of the execution, or you can call set_time_limit(n) in each iteration of a loop (for example) to reset the timer for n more seconds.
max_execution_time int. This sets the maximum time in seconds a script is allowed to run before it is terminated by the parser. This helps prevent poorly written scripts from tying up the server. The default setting is 30 . When running PHP from the command line the default setting is 0 .
The Maximum execution time of 30 seconds exceeded error is not related to Laravel but rather your PHP configuration.
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)
You can change the max_execution_time
to 300
seconds like max_execution_time = 300
You can find the path of your PHP configuration file in the output of the phpinfo
function in the Loaded Configuration File
section.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With