Bird
0
0

Identify the error in this PHP code intended to create a long-running server:

medium📝 Debug Q6 of 15
PHP - Request Lifecycle
Identify the error in this PHP code intended to create a long-running server:
Afwrite cannot be used with stream sockets.
Bstream_socket_server requires a callback function.
CThe port number 8080 is invalid in PHP.
DMissing fclose($conn) to close connection after writing.
Step-by-Step Solution
Solution:
  1. Step 1: Review socket handling

    After writing to the connection, the socket must be closed to free resources.
  2. Step 2: Identify missing fclose

    The code lacks fclose($conn), which can cause resource leaks.
  3. Final Answer:

    Missing fclose($conn) to close connection after writing. -> Option D
  4. Quick Check:

    Always close socket after writing [OK]
Quick Trick: Always close socket connections after use [OK]
Common Mistakes:
  • Assuming stream_socket_server needs callback
  • Thinking port 8080 is invalid
  • Believing fwrite can't write to sockets

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes