What is php max_execution_time actually measuring?

453 Views Asked by At

I have a web page which has a button on it that when clicked executes a single php function.

When a user clicks it, it takes 51081ms to return a page. 51376ms of this is something that's classed as 'Waiting' by the Network tab in my Firefox developer tools.

The max_execution_time declared in my php.ini file is 30. I can see this in my phpinfo file too.

My question is, how come my script doesn't time out after 30 seconds? What is max_execution_time actually measuring?

Edit to include code;

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'));

}

I understand which parts represent queries using Eloquent. So does my code go ;

php execution

php execution

database query

database query

database query

php execution... etc.?

Can someone explain to me what's going on 'under the hood'?

1

There are 1 best solutions below

4
t.niese On

set_time_limit says:

max_execution_time only affect the execution time of the script itself. Any time spent on activity that happens outside the execution of the script such as system calls using system(), stream operations, database queries, etc. is not included when determining the maximum time that the script has been running. This is not true on Windouws where the measured time is real.

So on Linux only the time used to execute php code is counted.

The waiting in the network tab just tells you that you didn’t get any response from the webserver until now.