minIntervalSeconds - (microtime(true) - $last); if ($remain > 0) { usleep((int) ceil($remain * 1_000_000)); } } finally { flock($handle, LOCK_UN); fclose($handle); } } /** * 记录本次 arXiv 请求已发出(用于下一次间隔计算)。 */ public function markSent(): void { $dir = storage_path('framework/cache'); $statePath = $dir.'/'.self::STATE_BASENAME; file_put_contents($statePath, (string) microtime(true)); } /** * @template T * * @param callable(): T $callback * @return T */ public function run(callable $callback): mixed { $this->waitTurn(); try { return $callback(); } finally { $this->markSent(); } } }