0

I want to the php script to simply end any communication without sending a single further packet so the browser is left waiting and waiting until it gives up.

My goal is to simulate and test a scenario when an HTTP server is accepting a connection but then freezing or taking an exceptionally long time to send further packets.

DG.
  • 3,417
  • 2
  • 23
  • 28
  • For anyone interested, I just stumbled upon a related question elsewhere: http://stackoverflow.com/questions/100841/artificially-create-a-connection-timeout-error – DG. Mar 30 '16 at 06:23

1 Answers1

1

If you terminate the HTTP connection, then the underlying TCP socket will get closed as well, and the browser will know immediately. I gather that this is not what you'd like. So, if you want to simulate a long timeout, then do just that:

sleep(315360000); // Sleep for 10 YEARS!

Note that conveniently PHP's script timeout will not happen while it's sleeping (or inside any other system call).

Vilx-
  • 104,512
  • 87
  • 279
  • 422
  • I'm not very familiar with the fine details of TCP/IP. If the server simply stopped responding (TCP socket released locally without sending any further packets to the client) would the browser "know immediately"? Would the host not simply keep waiting for further TCP packets until it timed out? – DG. Jun 03 '14 at 07:04
  • @DG - The TCP protocol does have service packets which are invisible to your program. That's how "connections" are established and reliability achieved (remember - the underlying IP protocol does not guarantee that the packets will arrive in the right order, or even arrive at all). So when you `close()` the socket, there are special packets that get sent and notify the other side. You could abandon the socket and just do nothing, but that would waste server resources (the OS would still think that you're using it so buffers and the like would remain active). – Vilx- Jun 03 '14 at 13:47
  • @DG - To perform the kind of "abandoning" that would actually simulate a severed cable would require quite a bit of complicated programming, and it anyway isn't possible from PHP/Apache, because they abstract away the sockets themselves, and you cannot operate on them directly. – Vilx- Jun 03 '14 at 13:48
  • @DG - If you're interested, the [wikipedia article](http://en.wikipedia.org/wiki/Transmission_Control_Protocol) seems to be quite thorough. – Vilx- Jun 03 '14 at 13:52
  • Thanks. Answer accepted. FYI, my new question: http://stackoverflow.com/questions/24132551/using-the-least-resources-possible-what-would-be-the-best-way-to-simulate-a-hun – DG. Jun 10 '14 at 03:53