0; --$i) { if (!file_exists($countFilename) || @unlink($countFilename)) { exit('Stopped'); } usleep(2); } exit('Cannot stop'); case 'start': touch($countFilename); default: if (!file_exists($countFilename)) { exit('Run prohibited'); } if (($fh = FileHelper::openAndLock($countFilename)) === false) { exit('Busy'); } $count = intval(FileHelper::readAll($fh)) + 1; } register_shutdown_function( function($fh, $count) { // write counter and unlock FileHelper::overwrite($fh, (string)$count); FileHelper::closeAndUnlock($fh); // call itself without get-parameters $path = $_SERVER['REQUEST_URI']; if (($p = strpos($path, '?')) !== false) { $path = substr($path, 0, $p); } $uri = HttpHelper::getUri($path); HttpHelper::callNoWait($uri); }, $fh, $count ); // ... do something ... echo 'Count: '.$count; usleep(100);