Does anyone know in which cases may infinite loop be useful in PHP?
Example :
<?php
while(true)
{
#..
}
?>
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Few Use cases.
1) If you are writing a program to allow input data for as long as the user wants, it just would not work to have the script loop 30,000 times or even 300,000,000 times. Instead, the code should loop forever, constantly accepting user input until the user ends the program by pressing Ctrl-C.
2) If you have some background process monitoring your servers continuously.
3) Possibly a very good usage is when your server script is listening to a socket for connections.
4) Video Game programming use them heavily.
I differ from some of the above answers posted above which say that “infinite loops are useless”.
http://devzone.zend.com/209/writing-socket-servers-in-php/ – An example of infinite loops been put to use.