Bird
0
0

What is wrong with this PHP script intended to simulate a Node.js server?

medium📝 Debug Q7 of 15
PHP - Request Lifecycle
What is wrong with this PHP script intended to simulate a Node.js server?
AThe infinite loop will cause memory leaks without closing connections.
Bstream_socket_accept cannot be used inside loops.
CThe server will crash because fwrite is asynchronous.
DThe error message is missing the error number.
Step-by-Step Solution
Solution:
  1. Step 1: Analyze loop behavior

    The infinite loop accepts connections and writes data but never closes them.
  2. Step 2: Identify resource leak

    Without fclose, connections remain open, causing memory/resource leaks over time.
  3. Final Answer:

    The infinite loop will cause memory leaks without closing connections. -> Option A
  4. Quick Check:

    Always close connections in loops [OK]
Quick Trick: Close connections inside loops to avoid leaks [OK]
Common Mistakes:
  • Thinking fwrite is asynchronous in PHP
  • Believing stream_socket_accept can't be looped
  • Ignoring resource cleanup in infinite loops

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes