Codice PHP:
while(true){ 
    if( 
controlla_stringa() ){
       break;
    } else {
        
sleep(5);
    }

questo può fare al caso tuo?