php 最大执行时间 30 秒超出 Laravel 4 错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19796201/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 20:02:43  来源:igfitidea点击:

Maximum execution time of 30 seconds exceeded Laravel 4 error

phphtmllaravellaravel-4

提问by Zach Starnes

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.

我在 laravel 4 中的 UserController 中发送密码请求的某个函数存在问题。它检查电子邮件是否存在于数据库中,然后在用户存在时发送电子邮件。然后,该函数在表中创建一个令牌,并在电子邮件中的链接末尾发送该令牌。

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 timeerror. 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!

该函数就像在数据库中创建令牌一样工作,但它似乎有问题,因为我不断收到Maximum execution time错误消息。我不知道是什么原因造成的,它似乎与重定向有关。有人可以帮帮我吗?提前致谢!

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:

这是 routes.php 文件:

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

采纳答案by Zach Starnes

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!

问题实际上出在我使用的 wifi 上。我断开连接并连接到另一个,一切正常。我从来没有遇到过 wifi 不允许本地主机发送电子邮件的问题。感谢所有的帮助!

回答by The Alpha

Your script executed for more then 30seconds and was terminated and not related to Laravelbut php. The default limit is 30seconds, stored in php.inifile. 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)

您的脚本执行了超过30几秒钟并被终止并且与Laravelbut无关php。默认限制为30秒,存储在php.ini文件中。要暂时延长时间限制,您可以在当前脚本中使用以下行 if 代码,但也尝试优化您的脚本(如果可能)

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

Read more on php manual.

阅读更多关于 php 手册。

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).

你可以做 set_time_limit(0); 这样脚本将永远运行 - 但是不建议这样做,并且您的 Web 服务器可能会因强加的 HTTP 超时(通常约为 5 分钟)而使您无法正常运行。

You may also use

你也可以使用

ini_set('max_execution_time', 60);

Check ini_set.

检查 ini_set。