file = $path . md5($name); if (!file_exists($this->file)) { @file_put_contents($this->file, ''); } } /** * 加锁执行 * @param Closure $func * @param bool $block * @return mixed */ public function execute($func, $block = true) { $fp = fopen($this->file, 'r'); $is_flock = $block ? flock($fp, LOCK_EX) : flock($fp, LOCK_EX | LOCK_NB); $call_back = null; if ($is_flock) { $call_back = $func(); flock($fp, LOCK_UN); } fclose($fp); return $call_back; } }