PHP Performance MCQ Test (with answers)

📊 PHP Performance MCQ Test

🟢 Basic Level

1. What is the main purpose of caching in PHP?

A. Increase database size
B. Reduce execution time
C. Increase server load
D. Slow down application

Answer: B


2. Which of the following is an opcode cache?

A. Redis
B. Memcached
C. OPcache
D. MySQL

Answer: C


3. Which function is faster?

A. print
B. echo
C. दोनों समान
D. None

Answer: B


4. What does isset() check?

A. Variable is empty
B. Variable exists and not null
C. Variable is false
D. Variable is numeric

Answer: B


5. Which is better for performance?

A. include
B. require
C. require_once
D. All same

Answer: C


🟡 Intermediate Level

6. Which caching is fastest?

A. File caching
B. Database caching
C. Memory caching (Redis)
D. Browser caching

Answer: C


7. What is the problem with this code?

for ($i = 0; $i < count($arr); $i++)

A. Syntax error
B. Infinite loop
C. Recalculates count each iteration
D. Nothing wrong

Answer: C


8. Which improves DB performance?

A. More queries
B. Indexing
C. Nested loops
D. Large data fetch

Answer: B


9. What does OPcache store?

A. Database queries
B. HTML output
C. Compiled PHP bytecode
D. CSS files

Answer: C


10. Which is best for session storage?

A. File
B. Cookie
C. Redis
D. URL

Answer: C


🔴 Advanced Level

11. What is N+1 query problem?

A. Too many loops
B. Queries inside loop
C. Syntax error
D. Memory leak

Answer: B


12. Which tool is used for profiling PHP?

A. Git
B. Xdebug
C. Apache
D. Bootstrap

Answer: B


13. What is PHP-FPM used for?

A. File storage
B. Fast request handling
C. Database connection
D. CSS optimization

Answer: B


14. Which header improves performance?

A. Content-Type
B. Cache-Control
C. Authorization
D. Accept

Answer: B


15. What does Gzip do?

A. Encrypt data
B. Compress response
C. Cache data
D. Execute faster

Answer: B


🧠 Scenario-Based MCQs

16. Website is slow due to repeated DB queries. Solution?

A. Add more queries
B. Use caching
C. Remove database
D. Restart server

Answer: B


17. High server load issue. Best fix?

A. Increase loops
B. Use CDN + caching
C. Disable PHP
D. Add HTML

Answer: B


18. Large API response delay. What to do?

A. Increase response size
B. Use pagination
C. Add images
D. Remove JSON

Answer: B


19. Memory limit exceeded. Fix?

A. Increase loops
B. Optimize code & unset variables
C. Add more variables
D. Ignore error

Answer: B


20. Best way to improve PHP performance instantly?

A. Disable server
B. Enable OPcache
C. Add CSS
D. Use print

Answer: B


🎯 Score Guide

  • 18–20 → 🔥 Expert
  • 14–17 → 🚀 Strong
  • 10–13 → 👍 متوسط (Good)
  • <10 → 📘 Need Practice