1. What is PHP and how does its shared-nothing request lifecycle work?
❓ Context: Explain the PHP shared-nothing architecture, how PHP-FPM processes HTTP requests, and memory cleanup between requests.
PHP (Hypertext Preprocessor) is a widely-used open-source general-purpose scripting language especially suited for web development and backend server APIs.
The Shared-Nothing Architecture:
Unlike Node.js or Java (where a single long-running server process stays alive in memory and shares variables across millions of incoming HTTP requests), PHP operates on a Shared-Nothing Request Lifecycle:
Why This Matters:
Because nothing is shared between requests, memory leaks in PHP scripts cannot crash the entire server over time! However, it also means you cannot store state (like user login sessions or WebSocket connections) in global PHP variables; you must use external storage like Redis, Memcached, or databases.
<?php
// Every HTTP request starts completely fresh!
// Global variables do NOT persist across different client requests.
$requestCount = 0;
$requestCount++;
echo "Request count: " . $requestCount;
// This will ALWAYS print "Request count: 1" for every visitor!
// When the request ends, $requestCount is destroyed from server RAM.
// To persist state across requests, use PHP Sessions (stored on disk/Redis):
session_start();
if (!isset($_SESSION['visits'])) {
$_SESSION['visits'] = 0;
}
$_SESSION['visits']++;
echo "Persistent visit count: " . $_SESSION['visits'];PHP destroys all memory and variables at the end of every HTTP request. Use external storage (Redis/Sessions) for persistent state.