🚧 Under construction — VoTechWorks is being built. A free tech program — complimentary, as our commitment to get America working.
voTechWorksGrade 13 · a vocational technology learning center, by urbanicity
newSchoolWorks.com › VoTechWorks › Technology & Design › Web & Software Development › PHP and Python Web Programming › Lesson 1
TEC-WEB46-03 · Lesson 1 · 9.5 clock hours · theory

How Server-Side Programming Works: The Request–Response Cycle

Objective. Students explain, without reference materials, how a browser request travels to a web server, is processed by a PHP or Python interpreter, and returns an HTTP response

⚠ Pending professional review

This lesson, its worked examples and its practice questions has not yet been verified by an industry-certified professional or by a certification or approval body. It is a study draft and may contain errors. Do not use it as instructions for work on a job site or on live equipment. Always follow your instructor, your supervising professional, and current official references and regulations.

VoTechWorks program approval and accreditation are still in progress. Credentials are issued only by the certifying bodies named in each program, after their own exams.

How Server-Side Programming Works: The Request–Response Cycle

Why This Matters

Every time a user loads a web page powered by PHP or Python, a precise chain of events takes place in milliseconds. Understanding that chain lets you build applications that work correctly, debug them when they break, and explain your code's behavior to teammates and clients. This lesson traces one complete round trip — from the user's browser to the server and back.

---

Step 1: The Browser Sends an HTTP Request

When a user types a URL into a browser or clicks a link, the browser first needs to resolve the domain name into a numeric IP address. It contacts a Domain Name System (DNS) resolver — usually provided by the user's ISP or a public service — which returns the IP address for the server hosting the site.

With the IP address in hand, the browser opens a TCP connection (or a TLS-encrypted connection for HTTPS) and sends an HTTP request. That request includes:

---

Step 2: The Web Server Receives the Request

The web server software — Apache HTTP Server or Nginx are the most common choices — listens on port 80 (HTTP) or port 443 (HTTPS). When the request arrives, the server inspects the path and decides what to do with it.

For a static file (an image, a CSS file, a plain HTML page), the server reads the file from disk and returns it immediately. No interpreter is involved.

For a dynamic resource (a `.php` file or a Python application endpoint), the server must hand the request off to an interpreter. It does this through one of two mechanisms:

Apache uses directives in its configuration files to define how these handoffs occur. Nginx uses `fastcgi_pass` or `proxy_pass` directives for the same purpose.

---

Step 3: The Interpreter Executes the Script

The interpreter (PHP or Python) receives the request data — method, headers, path, query string, and body — packaged as environment variables and input streams. The script then runs top to bottom:

1. It may validate and sanitize input.

2. It may query a database (MySQL, PostgreSQL, SQLite) using a driver or ORM.

3. It constructs an output — usually HTML, JSON, or XML.

4. It signals an HTTP status code (200 OK, 404 Not Found, 500 Internal Server Error, etc.) and any response headers.

If the interpreter process is not running or crashes, the web server cannot fulfill dynamic requests. Instead it returns an error — commonly 502 Bad Gateway (server could not get a valid response from the upstream process) or 503 Service Unavailable.

---

Step 4: The Response Returns to the Browser

The interpreter's output travels back through the web server, which adds its own headers (server name, date, caching directives) and sends the complete HTTP response to the browser. The response includes:

The browser reads the status code, parses the headers, renders the body, and may make additional requests for images, scripts, and stylesheets referenced in the page.

---

Operational Safety and Service Integrity

In a production environment, stopping or restarting interpreter services has real consequences for users. Always:

---

Putting It Together

The full path for one dynamic request:

Browser → DNS Resolver → Web Server (Apache/Nginx) → FastCGI/WSGI Interface → PHP or Python Interpreter → Database (if needed) → Interpreter Output → Web Server → Browser

Each arrow represents a handoff with a defined protocol. When something breaks — a 502 error, a blank page, or a database timeout — knowing which handoff failed tells you exactly where to look.

Key terms8

HTTP (HyperText Transfer Protocol)The application-layer protocol that defines how browsers and web servers exchange requests and responses, including methods such as GET and POST and status codes such as 200 and 404.
DNS (Domain Name System)A distributed naming system that translates human-readable domain names (e.g., example.com) into the numeric IP addresses web servers use.
Web serverSoftware such as Apache HTTP Server or Nginx that listens for incoming HTTP requests, serves static files directly, and delegates dynamic requests to an interpreter via CGI, FastCGI, or a proxy interface.
FastCGI / PHP-FPMFastCGI is a protocol that keeps an interpreter process running between requests; PHP-FPM (FastCGI Process Manager) is the standard implementation for PHP, allowing Apache or Nginx to hand requests to PHP efficiently.
WSGI (Web Server Gateway Interface)A standard interface between Python web applications and web servers, allowing servers such as Nginx to forward requests to Python application servers such as Gunicorn.
HTTP status codeA three-digit number in every HTTP response that indicates the outcome: 200 means success, 404 means the resource was not found, 500 means an internal server error, and 502 means the server received an invalid response from an upstream process.
Request bodyThe optional data payload included in HTTP POST or PUT requests, carrying information such as form field values or JSON data submitted by the user.
Response headersKey-value metadata sent by the server before the response body, including information such as content type, content length, caching rules, and cookies to set in the browser.
In class: Instructor-led diagram walkthrough: students label a blank request–response diagram (browser → DNS → web server → interpreter → database → response) and present their completed diagram to a partner · Read Apache/Nginx official documentation sections on how CGI and FastCGI pass requests to interpreters; students annotate three key paragraphs and write a one-paragraph plain-language summary · Hands-on comparison: students view the same URL with and without a running interpreter (stopping PHP-FPM deliberately) and record the error response, then restore service and document what changed
Materials: Apache HTTP Server docs, PHP manual (php.net), Python docs (docs.python.org), XAMPP or local Linux VM with Apache + PHP-FPM, whiteboard/digital diagram tool
Check: Students submit a correctly labeled request–response diagram and written summary; both must accurately describe all major steps — graded pass/fail with 80% accuracy on a 10-point checklist

Practice check8

Answer each question, then check it. Nothing is recorded; this is your own practice.

Networking concepts / CompTIA ITF+
1. A user types a URL into a browser. What is the FIRST network action the browser takes before sending an HTTP request?
Web server configuration / CompTIA Linux+
2. What HTTP status code would a browser most likely receive if a request reaches Nginx but PHP-FPM is not running?
Server-side architecture / CompTIA Linux+
3. Which mechanism allows a single PHP interpreter process to handle many requests in succession without restarting for each one?
Request–response cycle / CompTIA ITF+
4. What is the correct order of components in a complete dynamic-page request–response cycle?
Linux system administration / CompTIA Linux+
5. A student deliberately stops PHP-FPM and then visits a PHP page on their local development server. They record the error, then want to restore service. Which command correctly restarts PHP-FPM on a Linux system using systemd?
Python web frameworks / PCEP Python
6. Which Python interface standard plays the same role as FastCGI does for PHP, allowing a web server to forward requests to a Python application?
Web server concepts / CompTIA ITF+
7. When a web server returns a static HTML file, what component is NOT involved?
Professional and safe work practices / CompTIA Linux+
8. According to safe lab practices, where should a student stop and restart interpreter services when learning to observe error responses?
Record this lesson on my transcript. Sign in with your key and enrollment email to record lessons (enroll free if you have no key). This page stays open to read and practise.