PHP-CLI: Continue until user input...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
partiallynothing
Forum Commoner
Posts: 61
Joined: Fri Nov 21, 2003 5:02 pm
Location: connecticut, usa

PHP-CLI: Continue until user input...

Post 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!
Post Reply