Skip to content
Learn Netverks

Lesson

Step 4/36 11% through track

request-response-cycle

The HTTP request–response cycle

Last reviewed May 28, 2026 Content v20260528
Track mode
server_script
Means
Server runner
Reading
~2 min
Level
beginner

This lesson

This lesson teaches The HTTP request–response cycle: the syntax, APIs, and habits you need before advancing in PHP.

Teams ship The HTTP request–response cycle on every PHP codebase—skipping it leaves gaps in debugging and code reviews.

You will apply The HTTP request–response cycle in contexts like: LAMP/LEMP stacks, Laravel apps, WordPress themes/plugins, and shared hosting.

Write PHP in the editor and click Run on server—the dev runner executes your script and returns stdout/stderr (set LEARNING_RUNNER_ENABLED=true locally).

At the start of the track—complete before lessons that assume you understand the server playground.

Every PHP web page sits inside the HTTP request–response cycle. Understanding that cycle explains superglobals, sessions, headers, and why PHP cannot "push" data to a closed tab without another request or WebSockets elsewhere.

Steps in order

  1. Client request — browser or API client sends method (GET/POST), URL, headers, optional body
  2. Web server — routes the URL to a .php file or front controller (index.php)
  3. PHP bootstrap — autoloaders, config, session start (if used)
  4. Your logic — read input, validate, query DB, choose view
  5. Response — status line, headers (Content-Type, Set-Cookie), body (HTML/JSON)
  6. Process ends — unless using long-running workers (RoadRunner, FrankenPHP), the PHP process typically exits

Statelessness

HTTP is stateless: each request is independent. PHP remembers users via sessions (server storage + session cookie) or JWT/tokens in API designs. Do not assume variables from request A exist in request B.

Important interview questions and answers

  1. Q: What happens between clicking a link and seeing HTML?
    A: DNS → TCP/TLS → HTTP request → server runs PHP → HTML response → browser parses and renders.
  2. Q: Why is HTTP called stateless?
    A: The protocol does not inherently tie requests together; apps add cookies, sessions, or tokens to simulate state.
  3. Q: Where does PHP run in this chain?
    A: On the server after the web server receives the request and before the response is sent to the client.

Self-check

  1. What carries form data in a POST request—the URL or the body?
  2. Why must sessions use cookies or equivalent identifiers?

Interview prep

Why is HTTP stateless?

Each request is independent; PHP uses sessions, cookies, or tokens to remember users across requests.

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Playground

Runs on the configured server runner (dev: npm run runner with LEARNING_RUNNER_ENABLED=true). Output appears below the editor.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • What is CGI/FPM role?
  • Where does Apache fit?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump