private function warmCache($key) { if (self::$_cacheWarmupInitiated) { return; } self::$_cacheWarmupInitiated = true; // require apc for checking whether warmup is already in progress if (!function_exists('apc_fetch')) { return; } $key = "cache-warmup-{$key}"; // abort warming if a previous warmup started less than 10 seconds ago if (apc_fetch($key) !== false) { return; } // flag we are running a warmup for the current request apc_store($key, true, self::WARM_CACHE_TTL); $uri = $_SERVER["REQUEST_URI"]; $fp = fsockopen('127.0.0.1', 80, $errno, $errstr, 1); if ($fp === false) { error_log("warmCache - Couldn't open a socket [" . $uri . "]", 0); return; } $method = $_SERVER["REQUEST_METHOD"]; $out = "{$method} {$uri} HTTP/1.1\r\n"; $sentHeaders = self::getRequestHeaders(); $sentHeaders["Connection"] = "Close"; // mark request as a warm cache request in order to disable caching and pass the http/https protocol (the warmup always uses http) $sentHeaders[self::WARM_CACHE_HEADER] = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ? "https" : "http"; // if the request wasn't proxied pass the ip on the X-FORWARDED-FOR header if (!isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { $sentHeaders["X-FORWARDED-FOR"] = $_SERVER['REMOTE_ADDR']; $sentHeaders["X-FORWARDED-SERVER"] = kConf::get('remote_addr_header_server'); } foreach ($sentHeaders as $header => $value) { $out .= "{$header}:{$value}\r\n"; } $out .= "\r\n"; if ($method == "POST") { $postParams = array(); foreach ($_POST as $key => &$val) { if (is_array($val)) { $val = implode(',', $val); } $postParams[] = $key . '=' . urlencode($val); } $out .= implode('&', $postParams); } fwrite($fp, $out); fclose($fp); }