//Do something here - check a socket connection, monitor a database etc.
That will keep cycling until your condition becomes false. The user can call the page via their browser, click stop and the script will continue to run. It will however stop after the max_execution_time setting (often 30 - 60 seconds) so you may need to use set_time_limit(0) to override that (but some hosts disable that).
You use this function at your own risk and peril. Its dangerous in the wrong unenlightened hands because if you don't put in a check that will terminate the script, it can carry on running and eat up all the CPU resources of your server. If you're on a shared machine then your host will almost certainly shut you down. You MUST write in a clause that will stop the script - EG just checking if a file called stop.txt exists (or to avoid any path issues and the file never being fouind, check a database table or session instead).
Also in your loop be sure to use a delay such as sleep(1) to make the script sleep for a second. Why? Because if you don't the loop will try to run as fast as the processor will allow - eating the CPU usage again as described above. It will take over the CPU and lock out other processes that need it. You'll get shut down fast.