Easy way is to just put the rmdir in a loop
$tries = 0;
while($tries < 10 && !rmdir($root))
select(undef, undef, undef, 0.05);
if($tries < 10)
#unable to rmdir
Of course the sleep time and number of tries can be tweaked to your liking. This does not wait for just the .nfs files to be removed, if another process put files in the directory it waits for those to be removed too. Since you say it doesn't matter whether the directory is actually deleted, just that it doesn't print any error messages you may simply want to comment out all the carp lines.