0]); exit; } flock($fp, LOCK_EX); $count = (int) trim(stream_get_contents($fp)); if ($shouldIncrement) { $count++; ftruncate($fp, 0); rewind($fp); fwrite($fp, (string) $count); setcookie($cookieName, '1', time() + 86400, '/', '', true, true); } flock($fp, LOCK_UN); fclose($fp); echo json_encode(['count' => $count]);