function wp_cache_shutdown_callback() { global $cache_path, $cache_max_time, $file_expired, $file_prefix, $meta_file, $new_cache; global $wp_cache_meta_object, $known_headers, $blog_id; $wp_cache_meta_object->uri = $_SERVER["SERVER_NAME"] . preg_replace('/[ <>\'\\"\\r\\n\\t\\(\\)]/', '', $_SERVER['REQUEST_URI']); // To avoid XSS attacs $wp_cache_meta_object->blog_id = $blog_id; $wp_cache_meta_object->post = wp_cache_post_id(); $response = wp_cache_get_response_headers(); $wp_cache_meta_object->headers = array(); foreach ($known_headers as $key) { if (isset($response[$key])) { array_push($wp_cache_meta_object->headers, "{$key}: " . $response[$key]); } } /* Not used because it gives problems with some * PHP installations if (!$response{'Content-Length'}) { // WP does not set content size $content_size = ob_get_length(); @header("Content-Length: $content_size"); array_push($wp_cache_meta_object->headers, "Content-Length: $content_size"); } */ if (!$response['Last-Modified']) { $value = gmdate('D, d M Y H:i:s') . ' GMT'; /* Dont send this the first time */ /* @header('Last-Modified: ' . $value); */ array_push($wp_cache_meta_object->headers, "Last-Modified: {$value}"); } if (!$response['Content-Type'] && !$response['Content-type']) { $value = "text/html; charset=" . get_settings('blog_charset'); @header("Content-Type: {$value}"); array_push($wp_cache_meta_object->headers, "Content-Type: {$value}"); } ob_end_flush(); if ($new_cache) { $serial = serialize($wp_cache_meta_object); wp_cache_writers_entry(); $fr = fopen($cache_path . $meta_file, 'w'); fputs($fr, $serial); fclose($fr); wp_cache_writers_exit(); } if ($file_expired == false) { return; } // we delete expired files flush(); //Ensure we send data to the client wp_cache_phase2_clean_expired($file_prefix); }
function wp_cache_shutdown_callback() { global $cache_path, $cache_max_time, $file_expired, $file_prefix, $meta_file, $new_cache, $wp_cache_meta, $known_headers, $blog_id, $wp_cache_gzip_encoding, $gzsize, $cache_filename, $supercacheonly, $blog_cache_dir; global $wp_cache_blog_charset, $wp_cache_request_uri, $wp_cache_key; $wp_cache_meta['uri'] = $_SERVER["SERVER_NAME"] . preg_replace('/[ <>\'\\"\\r\\n\\t\\(\\)]/', '', $wp_cache_request_uri); // To avoid XSS attacks $wp_cache_meta['blog_id'] = $blog_id; $wp_cache_meta['post'] = wp_cache_post_id(); $wp_cache_meta['key'] = $wp_cache_key; $wp_cache_meta = apply_filters('wp_cache_meta', $wp_cache_meta); $response = wp_cache_get_response_headers(); foreach ($known_headers as $key) { if (isset($response[$key])) { $wp_cache_meta['headers'][$key] = "{$key}: " . $response[$key]; } } if (!isset($response['Last-Modified'])) { $value = gmdate('D, d M Y H:i:s') . ' GMT'; /* Dont send this the first time */ /* @header('Last-Modified: ' . $value); */ $wp_cache_meta['headers']['Last-Modified'] = "Last-Modified: {$value}"; } if (!$response['Content-Type'] && !$response['Content-type']) { // On some systems, headers set by PHP can't be fetched from // the output buffer. This is a last ditch effort to set the // correct Content-Type header for feeds, if we didn't see // it in the response headers already. -- dougal if (is_feed()) { $type = get_query_var('feed'); $type = str_replace('/', '', $type); switch ($type) { case 'atom': $value = "application/atom+xml"; break; case 'rdf': $value = "application/rdf+xml"; break; case 'rss': case 'rss2': default: $value = "application/rss+xml"; } } else { // not a feed $value = get_option('html_type'); if ($value == '') { $value = 'text/html'; } } $value .= "; charset=\"" . $wp_cache_blog_charset . "\""; if (isset($GLOBALS['wp_super_cache_debug']) && $GLOBALS['wp_super_cache_debug']) { wp_cache_debug("Sending 'Content-Type: {$value}' header.", 2); } @header("Content-Type: {$value}"); $wp_cache_meta['headers']['Content-Type'] = "Content-Type: {$value}"; } if (!$supercacheonly && $new_cache) { if ($wp_cache_gzip_encoding && !in_array('Content-Encoding: ' . $wp_cache_gzip_encoding, $wp_cache_meta['headers'])) { if (isset($GLOBALS['wp_super_cache_debug']) && $GLOBALS['wp_super_cache_debug']) { wp_cache_debug("Sending gzip headers.", 2); } $wp_cache_meta['headers']['Content-Encoding'] = 'Content-Encoding: ' . $wp_cache_gzip_encoding; $wp_cache_meta['headers']['Vary'] = 'Vary: Accept-Encoding, Cookie'; } $serial = serialize($wp_cache_meta); if (wp_cache_writers_entry()) { if (isset($GLOBALS['wp_super_cache_debug']) && $GLOBALS['wp_super_cache_debug']) { wp_cache_debug("Writing meta file: {$blog_cache_dir}meta/{$meta_file}", 2); } $tmp_meta_filename = $blog_cache_dir . 'meta/' . uniqid(mt_rand(), true) . '.tmp'; $fr = @fopen($tmp_meta_filename, 'w'); if (!$fr) { @mkdir($blog_cache_dir . 'meta'); } $fr = fopen($tmp_meta_filename, 'w'); fputs($fr, $serial); fclose($fr); @chmod($tmp_meta_filename, 0666 & ~umask()); if (!@rename($tmp_meta_filename, $blog_cache_dir . 'meta/' . $meta_file)) { unlink($blog_cache_dir . 'meta/' . $meta_file); rename($tmp_meta_filename, $blog_cache_dir . 'meta/' . $meta_file); } wp_cache_writers_exit(); } } global $time_to_gc_cache; if (isset($time_to_gc_cache) && $time_to_gc_cache == 1) { if (isset($GLOBALS['wp_super_cache_debug']) && $GLOBALS['wp_super_cache_debug']) { wp_cache_debug("Executing wp_cache_gc action.", 3); } do_action('wp_cache_gc'); } }
function wp_cache_shutdown_callback() { global $cache_path, $cache_max_time, $file_expired, $file_prefix, $meta_file, $new_cache, $wp_cache_meta_object, $known_headers, $blog_id, $wp_cache_gc, $wp_cache_gzip_encoding, $gzsize, $cache_filename; $wp_cache_meta_object->uri = $_SERVER["SERVER_NAME"] . preg_replace('/[ <>\'\\"\\r\\n\\t\\(\\)]/', '', $_SERVER['REQUEST_URI']); // To avoid XSS attacs $wp_cache_meta_object->blog_id = $blog_id; $wp_cache_meta_object->post = wp_cache_post_id(); $response = wp_cache_get_response_headers(); foreach ($known_headers as $key) { if (isset($response[$key])) { array_push($wp_cache_meta_object->headers, "{$key}: " . $response[$key]); } } /* Not used because it gives problems with some * PHP installations if (!$response{'Content-Length'}) { // WP does not set content size $content_size = ob_get_length(); @header("Content-Length: $content_size"); array_push($wp_cache_meta_object->headers, "Content-Length: $content_size"); } */ if (!isset($response['Last-Modified'])) { $value = gmdate('D, d M Y H:i:s') . ' GMT'; /* Dont send this the first time */ /* @header('Last-Modified: ' . $value); */ array_push($wp_cache_meta_object->headers, "Last-Modified: {$value}"); } if (!$response['Content-Type'] && !$response['Content-type']) { // On some systems, headers set by PHP can't be fetched from // the output buffer. This is a last ditch effort to set the // correct Content-Type header for feeds, if we didn't see // it in the response headers already. -- dougal if (is_feed()) { $type = get_query_var('feed'); $type = str_replace('/', '', $type); switch ($type) { case 'atom': $value = "application/atom+xml"; break; case 'rdf': $value = "application/rdf+xml"; break; case 'rss': case 'rss2': default: $value = "application/rss+xml"; } } else { // not a feed $value = 'text/html'; } $value .= "; charset=\"" . get_option('blog_charset') . "\""; @header("Content-Type: {$value}"); array_push($wp_cache_meta_object->headers, "Content-Type: {$value}"); } @ob_end_flush(); flush(); //Ensure we send data to the client if ($new_cache) { if ($wp_cache_gzip_encoding && !in_array('Content-Encoding: ' . $wp_cache_gzip_encoding, $wp_cache_meta_object->headers)) { array_push($wp_cache_meta_object->headers, 'Content-Encoding: ' . $wp_cache_gzip_encoding); array_push($wp_cache_meta_object->headers, 'Vary: Accept-Encoding, Cookie'); array_push($wp_cache_meta_object->headers, 'Content-Length: ' . $gzsize); } $serial = serialize($wp_cache_meta_object); if (!wp_cache_writers_entry()) { return false; } $tmp_meta_filename = tempnam($cache_path . 'meta/', "wp-cache"); $fr = @fopen($tmp_meta_filename, 'w'); if (!$fr) { @mkdir($cache_path . 'meta'); } $fr = fopen($tmp_meta_filename, 'w'); fputs($fr, $serial); fclose($fr); @chmod($tmp_meta_filename, 0666 & ~umask()); if (!@rename($tmp_meta_filename, $cache_path . 'meta/' . $meta_file)) { unlink($cache_path . 'meta/' . $meta_file); rename($tmp_metae_filename, $cache_path . 'meta/' . $meta_file); } wp_cache_writers_exit(); } if (!isset($wp_cache_gc)) { $wp_cache_gc = 3600; } $last_gc = get_option("wpsupercache_gc_time"); if (!$last_gc) { update_option('wpsupercache_gc_time', time()); return; } if ($last_gc > time() - $wp_cache_gc) { // do garbage collection once every X hours. return; } update_option('wpsupercache_gc_time', time()); // we delete expired files, using a wordpress cron event // since flush() does not guarantee hand-off to client - problem on Win32 and suPHP if (!wp_next_scheduled('wp_cache_gc')) { wp_schedule_single_event(time() + 10, 'wp_cache_gc'); } }