Page 1 of 1

PHP-CLI: Continue until user input...

Posted: Thu Jul 28, 2005 7:09 pm
by partiallynothing
I would like to implement a php script that would continue looping until the user entered the string "quit" followed by return.

I tried looking at while loops and do while loops with different implementations of STDIN, but in all cases the loop would not continue until the user entered something.

For example, this does not work:

Code: Select all

do {
	gfunc::dply_msg('Checking backend for an updated config...');
	// Logic to check for an updated config and to act on it if nessissary
	sleep(1);
	$quit = fgets(STDIN);
} while ( trim($quit) != 'quit');
The above script, php checks for an updated config file and then waits 1 second and then waits for user input

Here is what I want the script flow to be: check for an updated config file, sleep 1 seconds, check if the user entered quit, if not, continue

Anyone have any insight into my problem? Thanks!