>>368
いいんじゃないかな。
while文の所は・・・

while ($retry--) {
  return 0 if rename($lock_file, $lockex_file);
}
&error( 'Lock error' );

こうの方が良いかな。