Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maximum execution time of 30 seconds exceeded Laravel 4 error

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("[email protected]");
                });

                $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
like image 879
Zach Starnes Avatar asked Nov 05 '13 18:11

Zach Starnes


People also ask

How do you increase the maximum execution time of 30 seconds exceeded?

Change the execution time by adding the php_value max_execution_time 300 code—just as outlined above. Save changes and upload the edited file to your server to overwrite the old one. You can also increase the max_execution_time value by editing the wp-config. php file.

How do I fix max execution time of 60 seconds exceeded in laravel?

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. Save this answer.


2 Answers

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.

like image 164
The Alpha Avatar answered Oct 28 '22 06:10

The Alpha


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!

like image 32
Zach Starnes Avatar answered Oct 28 '22 04:10

Zach Starnes