What happens when the server is in an infinite loop and the client stops?

后端 未结 3 1161
眼角桃花
眼角桃花 2021-01-11 15:13

I am trying to figure out how the \"talking\" between the server and the client is done.

So, when the server is generating an infinite loop, echoing

相关标签:
3条回答
  • 2021-01-11 15:38

    The client (browser) has a TCP/IP session established with your server, waiting for the HTTP response of your website. When the user hits back/cancel/close, this TCP connection is closed immediately by the client.

    The webserver (i.e. apache) will inform the PHP interpreter of the TCP connection close.

    Unless the php.ini directive ignore_user_abort is set to 1 (on server side, 0 is PHP default), the PHP interpreter will then abort script execution when the current atomic operation finishes (in your example: echo())

    However, even when you set ignore_user_abort explicitly to 1 you will hit PHPs max_execution_time or the apache TimeOut (both are configurable on server side, too)

    also see ignore_user_abort() and set_time_limit()

    0 讨论(0)
  • 2021-01-11 15:47

    If you do set_time_limit(0); in the script (so the PHP interpreter lets it run forever), then the script will probably run until the web server kills it after however long the TimeOut variable is set to (defaults to 300 seconds I think, and as far as I know is only an Apache setting).

    See Apache's docs for the TimeOut directive.

    0 讨论(0)
  • 2021-01-11 15:56

    Even if your php script has an infinite loop, php.ini has a max_execution_time which will kill the process if the time exceeds.

    I am not sure how it will work when the client closes a connection. Apache might kill the process but I don't think PHP will be notified of the client's connection closing.

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