欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

maximum execution time of 30 seconds exceeded laravel

 

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?

 
   
what is id here? An index of the article array? – Kishor May 17 '15 at 11:25
   
What happens when you try $article = Article::orderBy('created_at', 'desc')->get(); instead of $article = Article::latest()->get(); or whatever time stamp field you have? – haakym May 17 '15 at 14:24
   
it turned out that my setup was faulty, xamp with laravel needs to have xdebug disabled for some reason – Geordie Gadgie May 18 '15 at 3:02

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.

 
   
Laravel routes on localhost are very very slow. Route::get('/', function() {die('here')}); shows 'here' string after 5 seconds. PHP7 + Apache. Windows 7 and Ubuntu 14.04 with the same behavior. – Maykonn May 11 '16 at 1:32
   
Updating max_execution_time is not a good solution. try to optimize the query. – Geo Tom May 7 at 7:01
   
instead of updating the configuration file use ini_set('max_execution_time', 300); in required pages.– Geo Tom May 7 at 7:04

it's a pure PHP setting. The alternative is to increase the execution time limit only for specific php scripts, by inserting on top of that php file, the following:

ini_set('max_execution_time', 180); //3 minutes
 
   
where should I add this in Laravel, when inserting this in the controller I get an error Namespace declaration statement has to be the very first statement or after any declare call in the script – davejal Mar 24 at 13:47
   
Ooh, I just placed it one line after the namespace line ... – davejal Mar 24 at 13:48

Sometimes you just need to optimize your code or query, Setting more max_execution_time is not a solution.

A code should not be run more than 30s.


来自 https://stackoverflow.com/questions/30270316/how-to-solve-a-timeout-error-in-laravel-5

 

 

I am having an issue with a certain function that sends a password request within my UserController in laravel 4. It checks to see if the email exists in the database then sends an email if the user does. The function then creates a token in a table and sends that at the end of the link within the email.

The function works as for as creating the token in the database but it seems to have an issue because i keep getting the Maximum execution time error. I do not know what is causing this, it seems to have something to do with the redirect. Can someone please help me? Thanks in advance!

Here is the controller function:

public function passwordRequest()
    {
        $data = [
            "requested"=>Input::old("requested")
        ];

        if(Input::server("REQUEST_METHOD") == "POST") {

            $input = Input::all();
            $rules = [
                "email" => "required|exists:users,email"
            ];
            $v = Validator::make($input, $rules);

            if($v->passes()) {
                $credentials = [
                    "email" => Input::get("email"),
                ];

                Password::remind($credentials, function($message, $user) {
                    $message->from("request@test.com");
                });

                $data["requested"] = true;

                return Redirect::route("user/request")->with($data);
            }

            return Redirect::to(URL::route("user/request"))->withInput($data)->withErrors($v);
        }

        return View::make("user/request", $data);
    }

here is the routes.php file:

Route::group(["before"=>"guest"], function() {
    Route::any("/", [
        "as"=>"user/login",
        "uses"=>"UserController@userLogin"
    ]);

    Route::any("/request", [
        "as"=>"user/request",
        "uses"=>"UserController@passwordRequest"
    ]);

    Route::any("/reset", [
        "as"=>"user/reset",
        "uses"=>"UserController@passwordReset"
    ]);

    Route::any("/register", [
        "as" => "user/register", 
        "uses" => "UserController@userRegister"
    ]);
})

;

here is the view if needed:

@extends("layouts.master")

@section("content")
<h1>Request Password Reset</h1>

{{ Form::open([
    "route"=>"user/request",
    "autocomplete"=>"off"
]) }}

    @if(isset($errors))
        @foreach ($errors->all() as $error)
            <div class="error">
                <li>{{ $error }}</li>
            </div>
        @endforeach
    @endif

    @if(Session::has("requested"))
        <div class="success">
            <li>An email has been sent with your password reset request.</li>
        </div>
        {{ Session::forget('requested') }}
    @endif
    <br />
    {{ Form::label("email", "Email:") }}
    {{ Form::text("email", Input::old("email"), [
        "placeholder"=>"Email Address"
    ]) }}

    {{ Form::submit("Reset") }}

{{ Form::close() }}
<br />
{{ HTML::linkRoute("user/login", "Return to Login") }}
@stop
asked Nov 5 '13 at 18:34
zachstarnes
81841433
 

Your script executed for more then 30 seconds and was terminated and not related to Laravel but php. The default limit is 30 seconds, stored in php.ini file. To temporarily extend the time limit, you may use following line if code in your current script, but try to optimize your script too (if possible)

set_time_limit(60); //60 seconds = 1 minute

Read more on php manual.

You can do set_time_limit(0); so that the script will run forever - however this is not recommended and your web server might catch you out with an imposed HTTP timeout (usually around 5 minutes).

You may also use

ini_set('max_execution_time', 60);

Check ini_set.

answered Nov 5 '13 at 18:52
The Alpha
93k15153198
 
2 
how can i add set_time_limit in laravel rather than php.ini? – Abhishek Kumar Jun 11 '14 at 7:41
   
   
@AbhishekKumar, In a service provider, probably in the appserviceprovider. – The Alpha Oct 1 '16 at 9:26
 

The problem was actually in the wifi I was using. I dissconnected from it and connected to another one and everything worked just fine. I have never had this issue where a wifi will not let the localhost send an email. Thanks for all the help!



来自 https://stackoverflow.com/questions/19796201/maximum-execution-time-of-30-seconds-exceeded-laravel-4...

 

Maximum execution time of 30 seconds exceeded

PUBLISHED 1 YEAR AGO BY JACKD

Hi, i am getting after signing up to my website when i host it in my web server

Maximum execution time of 30 seconds exceeded

any idea what should i do to avoid this?

regards, ci

RomainLanz

You can increase the maximum execution time in your php.ini file.

 
dancourse

Hi @Ci ,

There's a few ways to do it, (some borrowed from SO, http://stackoverflow.com/questions/7739870/increase-max-execution-time-for-php)

  1. Check if your script is doing something silly and taking ages when it shouldn't be, try dd($aVar);

  2. Increase the execution time at php.ini level, max_execution_time=300

  3. Use PHP at runtime to increase it, ini_set('max_execution_time', 300); //300 seconds = 5 minutes

  4. Use the .htaccess to increase it,

<IfModule mod_php5.c>
php_value max_execution_time 300
</IfModule>

#HTH

 
lk92
 lk92
7 months ago(19,810 XP)

i experience this also

i get following error from the laravel.log file

    local.ERROR: Symfony\Component\Debug\Exception\FatalErrorException: Maximum execution time of 30 seconds exceeded   
    in vendor/barryvdh/laravel-debugbar/src/DataCollector/QueryCollector.php:204

but only on my local environtment? how comes?

来自  https://laracasts.com/discuss/channels/general-discussion/maximum-execution-time-of-30-seconds-exceeded


普通分类: