ent-Type'] ) ) { $content_type = $response_headers['kv']['Content-Type']; } } $time = time(); $cache = $this->_get_cache( $this->_page_key_extension['group'] ); /** * Store different versions of cache */ $buffers = array(); $something_was_set = false; foreach ( $compressions_to_store as $_compression ) { $this->_set_extract_page_key( array_merge( $this->_page_key_extension, array( 'compression' => $_compression, 'content_type' => $content_type ) ), true ); if ( empty( $this->_page_key ) ) continue; // Compress content $buffers[$_compression] = $this->_compress( $buffer, $_compression ); // Store cache data $_data = array( '404' => $is_404, 'headers' => $headers, 'time' => $time, 'content' => $buffers[$_compression] ); if ( !empty( $_compression ) ) { $_data['c'] = $_compression; } if ( $has_dynamic ) $_data['has_dynamic'] = true; $_data = apply_filters( 'w3tc_pagecache_set', $_data, $this->_page_key, $this->_page_group ); if ( !empty( $_data ) ) { $cache->set( $this->_page_key, $_data, $this->_lifetime, $this->_page_group ); $something_was_set = true; } } if ( $something_was_set ) { $this->process_status = 'miss_fill'; } else { $this->process_status = 'miss_third_party'; } // Change buffer if using compression if ( defined( 'W3TC_PAGECACHE_OUTPUT_COMPRESSION_OFF' ) ) { $compression_header = false; } elseif ( $compression_of_returned_content && isset( $buffers[$compression_of_returned_content] ) ) { $buffer = $buffers[$compression_of_returned_content]; } // Calculate content etag $etag = md5( $buffer ); // Send headers $this->_send_headers( $is_404, $time, $etag, $compression_header, $headers ); return $buffer; } public function w3tc_usage_statistics_of_request( $storage ) { global $w3tc_start_microtime; $time_ms = 0; if ( !empty( $w3tc_start_microtime ) ) { $time_ms = (int)( ( microtime( true ) - $w3tc_start_microtime ) * 1000 ); $storage->counter_add( 'pagecache_requests_time_10ms', (int)( $time_ms / 10 ) ); } if ( !empty( $this->process_status ) ) { // see registered keys in PgCache_Plugin.w3tc_usage_statistics_metrics $storage->counter_add( 'php_requests_pagecache_' . $this->process_status, 1 ); if ( $this->_debug ) { self::log( 'finished in ' . $time_ms . ' size ' . $this->output_size . ' with process status ' . $this->process_status . ' reason ' . $this->cache_reject_reason); } } } /** * Log. */ static protected function log( $msg ) { $data = sprintf( "[%s] [%s] [%s] %s\n", date( 'r' ), isset( $_SERVER['REQUEST_URI'] ) ? filter_var( stripslashes( $_SERVER['REQUEST_URI'] ), FILTER_SANITIZE_URL ) : '', ! empty( $_SERVER['HTTP_REFERER'] ) ? htmlspecialchars( $_SERVER['HTTP_REFERER'] ) : '-', $msg ); $data = strtr( $data, '<>', '..' ); $filename = Util_Debug::log_filename( 'pagecache' ); return @file_put_contents( $filename, $data, FILE_APPEND ); } }