static function lock($path) { $lockPath = $path . '.lock'; //funx::debug(__FUNCTION__." $lockPath"); // get the lock $start = time(); while (@mkdir($lockPath) === false) { // delete stale lock clearstatcache(); if (file_exists($lockPath)) { $life = self::life($lockPath); if ($life > 5) { funx::debug(__FUNCTION__ . " {$lockPath}: unlocked ({$life} seconds stale)"); self::unlock($path); } } else { funx::debug(__FUNCTION__ . " {$lockPath}: cannot mkdir and path does not exist"); break; } //funx::debug(__FUNCTION__." $lockPath: waiting..."); usleep(100000); // a tenth of one second if (funx::wait($start, 15) === false) { funx::debug(__FUNCTION__ . " {$lockPath}: waited to long and didnt unlock (lock life={$life})"); break; } } return true; }