Table of Contents

3. Request Lifecycle — What Happens During a Request

Why the request lifecycle matters

To understand PHP, you must understand its rhythm.
Every PHP script lives inside a request, and that request defines:

AI often generates code that assumes a long‑running environment.
PHP is the opposite: everything begins and ends inside the request.

This page gives you the shape of that lifecycle.

1. The request arrives

A request reaches the server through:

The server hands the request to PHP, which starts with a clean slate:

Every request is a fresh world.


2. PHP loads the entry script

This is usually:

PHP begins executing the file top‑to‑bottom, registering declarations and running code as it encounters it.

This is where:

The architecture takes shape here.


3. The application runs

Inside the request, PHP:

Everything that happens, happens inside this one request.

There is no background memory.
No persistent objects.
No long‑lived services.

This is the heart of PHP’s simplicity.


4. Output is sent to the client

PHP sends output:

This includes:

Once output is sent, it cannot be “unsent”.
This is why mixing logic and output can cause subtle bugs
— especially when headers are involved.


5. The request ends

When the script finishes:

The next request starts from zero again.

This is the heart of PHP’s mental model.

Why this matters for AI‑generated code?

AI often assumes:

Your understanding of the request lifecycle helps you spot these mismatches instantly
— and correct them before they become architectural problems.