Запуск только одной копии скрипта

Bermuda

Новичок
Вопрос решен, может кому пригодится
PHP:
<?php
$lock_file = sys_get_temp_dir() . "/" . basename($_SERVER["PHP_SELF"]) . ".lock";

$fp = fopen($lock_file, "w+");
$res = flock($fp, LOCK_EX + LOCK_NB);
if (!$res) {
    print "Only one instance of the script is allowed to be running at a time, exiting...";
    exit();
}
?>
Функция sys_get_temp_dir (no version information, might be only in CVS).

Временная затычка
PHP:
<?php 
if (!function_exists('sys_get_temp_dir')) { 
    function sys_get_temp_dir() { 
        $temp_file = tempnam(md5(uniqid(rand(), TRUE)), ''); 
        if ($temp_file) { 
            $temp_dir = realpath(dirname($temp_file)); 
            unlink($temp_file); 
            return $temp_dir; 
        } else { 
            return FALSE; 
        } 
    } 
} 
?>
 
Сверху