Ultra simple HTTP socket server, written in PHP, behaving unexpectedly

前端 未结 1 755
失恋的感觉
失恋的感觉 2020-12-12 03:47

tldr;

  1. very minimal stream socket server in PHP
  2. acts strange since sometimes it successfully serves HTTP request and
相关标签:
1条回答
  • 2020-12-12 04:16

    You don't read the HTTP request from the client but instead simply send your response and close the connection. But closing the socket while there are still data to read will cause a connection reset send back to the client and that's what you will see in Chrome with ERR_CONNECTION_RESET. Other browsers might behave differently and it is also a timing issue if the browser can display the response before handling the reset.

    To fix it first read the full request from the client before you close the socket.

    0 讨论(0)
提交回复
热议问题