3

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'?

Jordan D
  • 718
  • 7
  • 21

1 Answers1

3

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.

t.niese
  • 39,256
  • 9
  • 74
  • 101
  • Thanks, I've expanded on my question because I'm still not sure what's really going on. – Jordan D Feb 14 '19 at 16:42
  • @JordanD Well those: `Event::find` , ... are all database queries. I don't know how many users are in `$userSlots` , but it could be possible that all of those db queries take from `21376` ms up to `50000` ms in total. So the actual execution time of the php script could be less then second. You should check if the DB library you use has some profiling options to see how many queries you issue per script and how long they last in total. – t.niese Feb 14 '19 at 16:52
  • OK, so my code does go; php execution, php execution, database query, database query, database query, php execution then? Are there actually 6 php executions in my code? – Jordan D Feb 14 '19 at 16:54
  • @JordanD You cannot really count the php executions as numbers of junks. Because on the one hand each `::where` call does execute further lines of php code before it queries the db and after it had queried the db and how should you define the junks. Imagine it more like you have to do some stuff in your house and someone is measuring the time you need for it. Most of it takes place in your house (php), but sometimes you need to go to hardware store (db query) to fetch something, the person measuring the time will pause measuring when you leaf the main door of the house. – t.niese Feb 14 '19 at 17:04