Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

php

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"hello<br />", for example, what happens when the client stops, or hits 'back'?

How does the server know it's the end of the loop or does it take an endless process by its side?

Is there anywhere I can read about it just to get the big picture?

like image 538
Ted Avatar asked Feb 27 '12 14:02

Ted


People also ask

What happens to the computer when you enter an infinite loop?

I hope nothing important happened to your computer! Nothing bad happens to the computer when you enter an infinite loop. Notice that the variable i is never incremented in the body of the loop, meaning that the condition of the while will never evaluate to false. An endless stream of the number 1 will be printed to console.

What is it called when a loop never ends?

# C# loops that don't end: infinite, or forever, loops An infinite loop is a loop that keeps running indefinitely (Liberty & MacDonald, 2009; Wikipedia, 2019). Even though the loop might have an exit condition, for whichever reason that condition isn't reached. And so the loop executes the same code over and over again.

What happens when you stop printing in an infinite loop?

Thanks a lot for the answer! In an infinite loop the computer does not have any way of knowing when you want to stop. The computer will keep printing and crash. you’re right!!

What is infinite loop also called endless loop?

Infinite loop also called endless loop… | by JAY TILLU | Jay Tillu | Medium What is Infinite Loop? The infinite loop also called endless loop is a type of loop that never ends. Instructions inside the loop will execute endlessly.


1 Answers

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()

like image 184
Kaii Avatar answered Nov 15 '22 20:11

Kaii