首页 > 解决方案 > php max_execution_time 实际测量的是什么?

问题描述

我有一个网页,上面有一个按钮,单击该按钮时会执行一个 php 函数。

当用户点击它时,返回一个页面需要51081ms。其中 51376 毫秒被我的 Firefox 开发人员工具中的“网络”选项卡归类为“等待”。

在我的 php.ini 文件中声明的 max_execution_time 是 30。我也可以在我的 phpinfo 文件中看到这一点。

我的问题是,为什么我的脚本在 30 秒后没有超时?max_execution_time 实际测量的是什么?

编辑以包含代码;

public function getSlotsByUser (Request $request) {

    $event_id = $request->event_id;
    $user_id = substr($request->user, 4);

    $event = Event::find($event_id);

    $user = User::find($user_id);

    $slots = TimeSlot::where('event_id',$event_id)->get();

    $userSlots = $user->slots;

    foreach($userSlots as $userSlot) {

       $guest = Guest::where('slot_id',$userSlot->id)->where('user_id',$user->id)->first();

       if($guest) {
            $userSlot->guest_id = $guest->id;
            $userSlot->guest_name = $guest->name . ' ' . $guest->surname;
        }
        else {
            $userSlot->guest_id = NULL;
            $userSlot->guest_name = NULL;
        }

        $userSlotIds[] = $userSlot->id;

    }

    $days = new DatePeriod(
         new DateTime($event->start_time),
         new DateInterval('P1D'),
         (new DateTime($event->end_time))->modify('+1 day')
    );

    return view('admin.calendar',compact('event','slots','user','userSlots','userSlotIds','days'));

}

我了解哪些部分代表使用 Eloquent 的查询。我的代码也是如此;

php执行

php执行

数据库查询

数据库查询

数据库查询

php执行...等等?

有人可以向我解释“引擎盖下”发生了什么吗?

标签: phpmax-execution-timeout

解决方案


set_time_limit说:

max_execution_time 只影响脚本本身的执行时间。在确定脚本运行的最长时间时,不包括在脚本执行之外发生的活动所花费的任何时间,例如使用 system() 的系统调用、流操作、数据库查询等。这在测量时间是真实的 Windows 上是不正确的。

所以在 Linux 上只计算用于执行 php 代码的时间。

网络选项卡waiting中的 只是告诉您直到现在您还没有从网络服务器得到任何响应。


推荐阅读