What happens to a PHP script during a single web request?
The PHP script is loaded, executed from start to finish, and then the process ends. Each request starts a new process or thread that runs the script independently.
Click to reveal answer
beginner
Why does PHP use a process model per request?
To keep each request isolated, so errors or data from one request do not affect others. This makes PHP simple and secure for web applications.
Click to reveal answer
beginner
How does PHP handle variables and memory between requests?
Variables and memory are created fresh for each request and destroyed when the request ends. PHP does not keep variables or memory between requests.
Click to reveal answer
intermediate
What is the role of the web server in PHP's process model?
The web server receives the request, starts a PHP process or thread to run the script, then sends the output back to the client after the script finishes.
Click to reveal answer
intermediate
How does PHP's process model affect performance?
Starting a new process for each request adds some overhead, but PHP uses techniques like opcode caching to speed up execution and reduce delays.
Click to reveal answer
What happens to PHP variables after a web request finishes?
AThey are sent to the client browser
BThey are saved automatically for the next request
CThey are destroyed and do not persist to the next request
DThey become global variables
✗ Incorrect
PHP variables exist only during the request and are destroyed afterward to keep requests isolated.
Which component starts the PHP process for each request?
AThe client browser
BThe operating system scheduler
CThe database
DThe web server
✗ Incorrect
The web server receives the request and starts the PHP process to run the script.
Why does PHP create a new process for each request?
ATo isolate requests and avoid data sharing
BTo save memory between requests
CTo keep variables persistent
DTo speed up the server startup
✗ Incorrect
Isolating requests prevents errors or data leaks between users.
What technique helps PHP reduce the overhead of starting a process each request?
AOpcode caching
BDatabase indexing
CClient-side scripting
DSession cookies
✗ Incorrect
Opcode caching stores compiled code to speed up script execution.
In PHP's process model, when does the script execution end?
AWhen the user logs out
BAt the end of the request
CAfter 10 requests
DWhen the server restarts
✗ Incorrect
Each script runs only during its request and ends when the request finishes.
Explain how PHP handles a web request from start to finish in its process model.
Think about what happens each time you load a PHP page in your browser.
You got /6 concepts.
Describe the advantages and disadvantages of PHP's process model per request.
Consider both how it helps and what challenges it creates.
You got /5 concepts.
Practice
(1/5)
1. What happens to PHP variables after a web request finishes?
easy
A. They become global variables accessible by all users
B. They keep their values for the next request automatically
C. They are stored permanently in the server memory
D. They are reset and lost unless saved externally
Solution
Step 1: Understand PHP request lifecycle
PHP starts fresh for each request, so variables exist only during that request.
Step 2: Identify variable persistence
Variables reset after request ends unless saved in sessions or databases.
Final Answer:
They are reset and lost unless saved externally -> Option D
Quick Check:
PHP variables reset each request = D [OK]
Hint: Remember: PHP starts fresh every request, no variable memory [OK]
Common Mistakes:
Thinking variables persist automatically between requests
Confusing PHP with long-running server processes
Assuming global variables keep values across users
2. Which PHP code snippet correctly shows the start of a new request process?
easy
A.
B.
C.
D.
Solution
Step 1: Analyze variable initialization
In a new request, variables start fresh; $count = 0 sets it properly.
Step 2: Check other options for persistence
Options A, B, D try to increment without initialization or rely on static/session which need extra setup.
Final Answer:
<?php $count = 0; echo $count; ?> -> Option C
Quick Check:
New request means fresh variables = C [OK]
Hint: Fresh request means variables start from scratch [OK]
Common Mistakes:
Assuming static variables keep value across requests
Using session without starting it
Incrementing uninitialized variables
3. What will be the output of this PHP code when run twice in separate requests?