0
0
PHPprogramming~10 mins

PHP process model per request - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - PHP process model per request
Client sends HTTP request
Web server receives request
Web server starts PHP process
PHP process initializes environment
PHP executes script from start to end
PHP sends output to web server
Web server sends response to client
PHP process ends and cleans up
Each HTTP request starts a new PHP process that runs the script fully, then ends, sending output back to the client.
Execution Sample
PHP
<?php
// Simple PHP script
echo "Hello, world!";
This script runs once per request, outputs text, then the PHP process ends.
Execution Table
StepActionState/OutputNotes
1Client sends HTTP requestRequest received by web serverStart of process
2Web server starts PHP processNew PHP process createdIsolated environment for this request
3PHP initializes environmentVariables, settings readyFresh start for each request
4PHP executes scriptOutputs 'Hello, world!'Script runs top to bottom
5PHP sends output to web serverOutput buffered and sentResponse ready for client
6Web server sends responseClient receives 'Hello, world!'End user sees output
7PHP process endsMemory and resources freedNo state saved for next request
💡 PHP process ends after script execution, no persistent state kept.
Variable Tracker
VariableStartAfter script executionFinal
Output bufferEmpty"Hello, world!"Sent and cleared
MemoryCleanUsed during scriptFreed after process ends
Key Moments - 3 Insights
Why does PHP start a new process for each request?
Because PHP is designed to run scripts fresh each time, ensuring no leftover data or state from previous requests, as shown in execution_table steps 2 and 7.
Does PHP keep variables or data between requests?
No, each PHP process ends after the request, clearing all variables and memory (see execution_table step 7 and variable_tracker).
What happens to the output generated by PHP?
The output is buffered during script execution and sent to the web server, which then sends it to the client (execution_table steps 4 and 5).
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, at which step does PHP send the output to the web server?
AStep 5
BStep 4
CStep 6
DStep 7
💡 Hint
Check the 'Action' column in execution_table row 5.
According to variable_tracker, what happens to memory after the PHP process ends?
AMemory is kept for next request
BMemory is freed
CMemory is doubled
DMemory is saved to disk
💡 Hint
Look at the 'Memory' row in variable_tracker, final column.
If PHP did not start a new process per request, what would change in the execution flow?
AWeb server would not receive requests
BOutput would not be sent
CStep 7 would not free memory
DClient would not send requests
💡 Hint
Consider the importance of process cleanup in execution_table step 7.
Concept Snapshot
PHP process model per request:
- Each HTTP request starts a new PHP process
- PHP runs the script from start to end
- Output is sent to the web server
- Process ends, freeing all memory
- No data persists between requests
Full Transcript
When a client sends an HTTP request, the web server starts a new PHP process. This process initializes a fresh environment and runs the PHP script from top to bottom. The script generates output, which PHP sends back to the web server. The web server then sends this response to the client. After the script finishes, the PHP process ends and frees all memory and variables. This means PHP does not keep any data between requests, ensuring each request is handled independently.