while (true) { if(file_exists($newFileName)) { mediaToFlv($newFileName,$destFlvPath); break; } sleep(1); }