/** * Standard output handler for use with ob_start * * @param $s string * * @return string */ function wfOutputHandler($s) { global $wgDisableOutputCompression, $wgValidateAllHtml; $s = wfMangleFlashPolicy($s); if ($wgValidateAllHtml) { $headers = apache_response_headers(); $isHTML = true; foreach ($headers as $name => $value) { if (strtolower($name) == 'content-type' && strpos($value, 'text/html') === false && strpos($value, 'application/xhtml+xml') === false) { $isHTML = false; break; } } if ($isHTML) { $s = wfHtmlValidationHandler($s); } } if (!$wgDisableOutputCompression && !ini_get('zlib.output_compression')) { if (!defined('MW_NO_OUTPUT_COMPRESSION')) { $s = wfGzipHandler($s); } if (!ini_get('output_handler')) { wfDoContentLength(strlen($s)); } } return $s; }
/** * Remember that this is not sanitized and should be commented out of your code when done using */ function debugRequest() { echo "Echoing for debug:<br>"; echo "You should see 'DONE' line at the end if all is successful<br>"; function show($arr, $label = "") { echo "{$label}<br>"; echo "<pre>"; var_dump($arr); echo "</pre>"; echo "<br>"; } // === Section 1 show($_GET, "GET"); show($_POST, "POST"); show($_COOKIE, "COOKIE"); show($_SERVER, "SERVER"); show(getallheaders(), "Request headers"); show(apache_response_headers(), "Response headers: apache_response_headers (array)"); // Section 1 === if (isset($_COOKIE["thetestcookie"])) { echo "thetestcookie:" . $_COOKIE["thetestcookie"] . "<br>"; } else { echo "thetestcookie: cookie is not set<br>"; } echo "<br><br>Usage notes:<br>"; $readme = ""; $readme .= "- You can set a cookie called 'thetestcookie'"; echo $readme; echo "<br>DONE<br>"; }
/** * Captures data about the current environment, before a notification * @return array * @access private */ function prepareData() { global $HTTP_RAW_POST_DATA; $Data = array('timestamp' => time(), 'gmt' => gmdate("D, d M Y H:i:s", time()) . " GMT", 'requestInfo' => $this->requestInfo, 'responseInfo' => $this->responseInfo, 'SERVER' => $_SERVER, 'GET' => $_GET, 'POST' => $_POST, 'RAWPOST' => $HTTP_RAW_POST_DATA); if (function_exists('apache_request_headers')) { $Data['requestHeaders'] = apache_request_headers(); $Data['responseHeaders'] = apache_response_headers(); } return $Data; }
protected static function getHeaders() { if (function_exists('apache_response_headers')) { return apache_response_headers(); } else { $headers = array(); foreach (headers_list() as $header) { $sp = strpos($header, ':'); $headers[substr($header, 0, $sp)] = substr($header, $sp); } return $headers; } }
function store() { header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); $cache = ""; foreach (apache_response_headers() as $key => $value) { if ('set-cookie' != strtolower($key)) { $cache .= $key . ': ' . $value . "\r\n"; } } $cache .= "\r\n"; $cache .= ob_get_flush(); file_put_contents($this->_filename, $cache); }
function wp_cache_get_response_headers() { if (function_exists('apache_response_headers')) { $headers = apache_response_headers(); } else { if (function_exists('headers_list')) { $headers = array(); foreach (headers_list() as $hdr) { list($header_name, $header_value) = explode(': ', $hdr, 2); $headers[$header_name] = $header_value; } } else { $headers = null; } } return $headers; }
public function execute() { $back = 'Request headers:<ul>' . PHP_EOL; foreach (apache_request_headers() as $key => $v) { $back .= sprintf('<li>%s: %s</li>' . PHP_EOL, htmlspecialchars($key), htmlspecialchars($v)); } $back .= '</ul><br/><br/><ul>Response Headers:<ul>' . PHP_EOL; foreach (apache_response_headers() as $key => $v) { $back .= sprintf('<li>%s: %s</li>' . PHP_EOL, htmlspecialchars($key), htmlspecialchars($v)); } $back .= '</ul>' . PHP_EOL; if (GWF_User::getStaticOrGuest()->isAdmin()) { $back .= '<br/><br/>$_SERVER variables:<ul>'; foreach ($_SERVER as $key => $v) { $back .= sprintf('<li>%s: %s</li>' . PHP_EOL, htmlspecialchars($key), htmlspecialchars($v)); } $back .= '</ul>'; } return $back; }
public static function handleOnShutdown() { $request = self::_getRequest(); if (!$request->three_o_four_buffering_started) { return; } $response = ob_get_clean(); if (http_response_code() != 200) { ob_end_flush(); return; } $contentLength = strlen($response); $etag = null; if (isset($request->three_o_four_cache_response) && $request->three_o_four_cache_response == true) { $key = self::_generateCacheKey($request); $microtime = microtime(); //$etag = md5($key . $microtime); $etag = self::_hash($response); $cacheData = array('changed' => $microtime, 'etag' => $etag, 'contentLength' => $contentLength, 'content' => $response, 'headers' => apache_response_headers(), 'params' => array()); if (isset($request->three_o_four_cache_opts['store_params'])) { foreach ($request->three_o_four_cache_opts['store_params'] as $k) { if (isset($request->url_params[$k])) { $cacheData['params'][$k] = $request->url_params[$k]; } } } // Optimization for pages cache_set($key, $cacheData); cache_save(); } else { if (isset($request->three_o_four_emit_etag) && $request->three_o_four_emit_etag == true) { $etag = self::_hash($response); } } self::_sendResponse($response, $contentLength, $etag); }
/** * Show HTTP headers * @return JBDump */ public static function headers() { if (!self::isDebug()) { return false; } if (function_exists('apache_request_headers')) { $data = array('Request' => apache_request_headers(), 'Response' => apache_response_headers(), 'List' => headers_list()); } else { $data = array('List' => headers_list()); } if (headers_sent($filename, $linenum)) { $data['Sent'] = 'Headers already sent in ' . self::i()->_getRalativePath($filename) . ':' . $linenum; } else { $data['Sent'] = false; } return self::i()->dump($data, '! headers !'); }
function ob($output) { if ($this->cancel !== false) { return $output; } // PHP5 and objects disappearing before output buffers? wp_cache_init(); // Remember, $wp_object_cache was clobbered in wp-settings.php so we have to repeat this. $this->configure_groups(); // Do not batcache blank pages (usually they are HTTP redirects) $output = trim($output); if (empty($output)) { return; } // Construct and save the batcache $cache = array('output' => $output, 'time' => time(), 'timer' => $this->timer_stop(false, 3), 'status_header' => $this->status_header, 'version' => $this->url_version); if (function_exists('apache_response_headers')) { $cache['headers'] = apache_response_headers(); if (!empty($this->uncached_headers)) { foreach ($cache['headers'] as $header => $value) { if (in_array(strtolower($header), $this->uncached_headers)) { unset($cache['headers'][$header]); } } } } wp_cache_set($this->key, $cache, $this->group, $this->max_age + $this->seconds + 30); // Unlock regeneration wp_cache_delete("{$this->url_key}_genlock", $this->group); if ($this->cache_control) { header('Last-Modified: ' . date('r', $cache['time']), true); header("Cache-Control: max-age={$this->max_age}, must-revalidate", false); } if (!empty($this->headers)) { foreach ($this->headers as $k => $v) { if (is_array($v)) { header("{$v[0]}: {$v[1]}", false); } else { header("{$k}: {$v}", true); } } } // Add some debug info just before </head> if ($this->debug) { $tag = "<!--\n\tgenerated in " . $cache['timer'] . " seconds\n\t" . strlen(serialize($cache)) . " bytes batcached for " . $this->max_age . " seconds\n-->\n"; if (false !== ($tag_position = strpos($output, '</head>'))) { $tag = "<!--\n\tgenerated in " . $cache['timer'] . " seconds\n\t" . strlen(serialize($cache)) . " bytes batcached for " . $this->max_age . " seconds\n-->\n"; $output = substr($output, 0, $tag_position) . $tag . substr($output, $tag_position); } } // Pass output to next ob handler return $output; }
function misc_proxy($url, $translate_func, $flags) { // $res_keys = $http_response_header; // deprecated $res = apache_response_headers(); $res_keys = array_keys($res); $req = apache_request_headers(); $req_keys = array_keys($req); if (($fp = fopen($url, "rb")) == false) { return -1; } $p = ""; $i_max = sizeof($res_keys); /* for ($i = 1; $i < $i_max; $i++) { if (!strncasecmp ($res[$res_keys[$i]], "Content-Type: ", 14)) { if ($res[$res_keys[$i]] == "Content-Type: audio/mpeg" || $res[$res_keys[$i]] == "Content-Type: application/octet-stream") $p .= "Content-Disposition: attachment; filename=".$file; } else $p .= $res[$res_keys[$i]]; $p .= $res_keys[$i]; } header ($p); */ if ($flags & PROXY_SHOW_HEADER) { $p = "<!--\n"; $j_max = sizeof($req_keys); for ($j = 0; $j < $j_max; $j++) { $p .= $req_keys[$j] . ": " . $req[$req_keys[$j]] . "\n"; } $p .= "\n\n\n\n"; for ($i = 0; $i < $i_max; $i++) { $p .= $res_keys[$i] . ": " . $res[$res_keys[$i]] . "\n"; } $p .= "\n//-->"; echo $p; } if ($translate_func || $flags & PROXY_PASS_FORMS || $flags & PROXY_PASS_LINKS) { while ($p = fgets($fp)) { echo $translate_func($p); } } else { fpassthru($fp); } fclose($fp); return 0; }
function __tcSqlLogDump() { global $__tcSqlLog, $__tcPageEndTime; global $service, $memcache; static $sLogPumped = false; if (!empty($sLogPumped)) { return; } $sLogPumped = true; __tcSqlLogPoint('shutdown'); $headers = array(); if (function_exists('apache_response_headers') || function_exists('headers_list')) { if (function_exists('apache_response_headers')) { flush(); $headers = apache_response_headers(); } else { $headers = headers_list(); } } $commentBlosk = false; foreach ($headers as $row) { if (strpos($row, '/xml') !== false || strpos($row, '+xml') !== false) { /* To check text/xml, application/xml and application/xml+blah, application/blah+xml... types */ $commentBlosk = true; break; } if (strpos($row, 'text/javascript') !== false) { return; } } if ($commentBlosk == true) { echo '<!--'; } if (!$commentBlosk) { print <<<EOS <style type='text/css'> /*<![CDATA[*/ \t.debugTable \t{ \t\tbackground-color: #fff; \t\tborder-left: 1px solid #999; \t\tborder-top: 1px solid #999; \t\tborder-collapse: collapse; \t\tmargin-bottom: 20px; \t} \t.debugTable * \t{ \t\tborder: none; \t\tmargin: 0; \t\tpadding: 0; \t} \t.debugTable td, .debugTable th \t{ \t\tborder-bottom: 1px solid #999; \t\tborder-right: 1px solid #999; \t\tcolor: #000; \t\tfont-family: Arial, Tahoma, Verdana, sans-serif; \t\tfont-size: 12px; \t\tpadding: 3px 5px; \t} \t.debugTable th \t{ \t\tbackground-color: #dedede; \t\ttext-align: center; \t} \ttr.debugSQLLine .rows \t{ \t\ttext-align: center; \t} \ttr.debugSQLLine .error \t{ \t\ttext-align: left; \t} \ttr.debugSQLLine .elapsed, tr.debugSQLLine .elapsedSum \t{ \t\ttext-align: right; \t} \ttr.debugSQLLine .backtrace \t{ \t\tfont-family: Courier, 'Courier new', monospace; \t\tfont-size: 11px; \t\tletter-spacing: -1px; \t} \ttr.debugCached *, tr.debugSystem * \t{ \t\tcolor: #888888 !important; \t} \t/* warning */ \ttr.debugWarning * \t{ \t\tbackground-color: #fefff1; \t\tcolor: #4b4b3b !important; \t} \ttr.debugWarning th \t{ \t\tbackground-color: #e5e5ca; \t} \t/* error */ \ttr.debugError * \t{ \t\tbackground-color: #fee5e5; \t\tcolor: #961f1d !important; \t} \ttr.debugError th \t{ \t\tbackground-color: #fccbca; \t} \ttfoot td \t{ \t\tpadding: 15px !important; \t\ttext-align: center; \t} /*]]>*/ </style> EOS; } $elapsed_total_db = 0; $elapsed = array(); $count = 1; $cached_count = 0; foreach ($__tcSqlLog as $c => $log) { $elapsed[$count] = array($log['elapsed'], $count, $log['cached'] ? "cached" : ""); $__tcSqlLog[$c]['percent'] = sprintf("%4.1f", $log['endtime'] * 100 / $__tcPageEndTime); $count++; } arsort($elapsed); $bgcolor = array(); foreach (array_splice($elapsed, 0, 5) as $e) { if ($e[2] != "cached") { $top5[$e[1]] = true; } } $count = 1; if (!$commentBlosk) { print '<table class="debugTable">'; print <<<THEAD \t\t<thead> \t\t\t<tr> \t\t\t\t<th>count</th><th class="sql">query string</th><th>elapsed (ms)</th><th>elapsed sum (ms)</th><th></th><th>rows</th><th>error</th><th>stack</th> \t\t\t</tr> \t\t</thead> THEAD; print '<tbody>'; } foreach ($__tcSqlLog as $c => $log) { $error = ''; $backtrace = ''; $frame_count = 1; $backtrace = __tcSqlLoggetCallstack($log['backtrace']); if ($log['errno']) { $error = "Error no. {$log['errno']} : {$log['error']}"; } $trclass = ''; $count_label = $count; if (!empty($error)) { $trclass = ' debugError'; } else { if (isset($top5[$count])) { $trclass = ' debugWarning'; } else { if ($log['cached'] == 1) { $error = "(cached)"; $trclass .= ' debugCached'; $cached_count++; } else { if ($log['cached'] == 2) { $error = ""; $trclass .= ' debugCached'; $count_label = ''; $backtrace = ''; } } } } if ($log['sql'] == '[shutdown]') { $error = ""; $log['sql'] = 'Shutdown'; $trclass .= ' debugSystem'; $count_label = ''; $backtrace = ''; } $elapsed_total_db += $log['elapsed']; $elapsed_total = $log['endtime']; $progress_bar = $log['percent'] / 2; //Max 50px; if (!$commentBlosk) { $log['sql'] = htmlspecialchars($log['sql']); $log['percent'] = "<div style='background:#f00;line-height:10px;width:{$progress_bar}px'> </div>"; print <<<TBODY \t\t<tr class="debugSQLLine{$trclass}"> \t\t\t<th>{$count_label}</th> \t\t\t<td class="code"><code>{$log['sql']}</code></td> \t\t\t<td class="elapsed">{$log['elapsed']}</td> \t\t\t<td class="elapsedSum">{$log['endtime']}</td> \t\t\t<td class="elapsedSum">{$log['percent']}</td> \t\t\t<td class="rows">{$log['rows']}</td> \t\t\t<td class="error">{$error}</td> \t\t\t<td class="backtrace"><pre>{$backtrace}</pre></td> \t\t</tr> TBODY; } else { $log['sql'] = str_replace('-->', '-- >', $log['sql']); print <<<TBODY =============================================================================================== {$count_label}:{$log['sql']} Elapsed:{$log['elapsed']} ms/End time:{$log['endtime']}/Percent:{$log['percent']}/Rows:{$log['rows']} rows {$error} {$backtrace} TBODY; } if ($log['cached'] < 2) { $count++; } } $count--; $real_query_count = $count - $cached_count; if (!$commentBlosk) { print '</tbody>'; print <<<TFOOT <tfoot> \t<tr> \t\t<td colspan='8'> \t\t{$count} ({$real_query_count}+{$cached_count} cache) Queries <br /> \t\t{$elapsed_total_db} ms elapsed in db query, overall {$elapsed_total} ms elapsed \t\t</td> \t</tr> </tfoot> TFOOT; print '</table>'; } global $service, $URLInfo, $suri; print '<div class="debugTable">' . CRLF; print '<h4>Current Database Management System :</h4>' . CRLF . '<p>' . POD::dbms() . ' ' . POD::version() . '</p>' . CRLF; print '<h4>SSL support : </h4>' . CRLF; if (isset($service['useSSL']) && $service['useSSL'] == true) { print '<p>Enabled</p>' . CRLF; } else { print '<p>Disabled</p>' . CRLF; } print '<h4>Cache system :</h4>' . CRLF; if (isset($service['pagecache']) && $service['pagecache'] == true) { print '<p>Page cache Enabled</p>' . CRLF; } else { print '<p>Page cache Disabled</p>' . CRLF; } if (isset($service['skincache']) && $service['skincache'] == true) { print '<p>Skin cache Enabled</p>' . CRLF; } else { print '<p>Skin cache Disabled</p>' . CRLF; } if (isset($service['memcached']) && $service['memcached'] == true) { print '<p>Memcached module Enabled</p>' . CRLF; } else { print '<p>Memcached module Disabled</p>' . CRLF; } if (!empty($service['debug_session_dump'])) { print '<h4>Session Information</h4>' . CRLF; print '<pre>session_id = ' . session_id() . CRLF; print '$_SESSION = '; print_r($_SESSION); print '$_COOKIE = '; print_r($_COOKIE); print '</pre>'; } if (!empty($service['debug_rewrite_module'])) { print '<h4>Path parse result</h4>' . CRLF; print '<pre>' . CRLF; print_r($URLInfo); print_r($suri); print '</pre>'; } print '</div>' . CRLF; if ($commentBlosk == true) { echo '-->'; } }
function _onShutdownKtai() { if (!$this->HypKTaiRender->vars['ua']['allowCookie']) { $url = ''; $arh = FALSE; if (function_exists('apache_response_headers')) { $arh = apache_response_headers(); if (is_array($arh)) { foreach (array('Location', 'location', 'LOCATION') as $key) { if (isset($arh[$key])) { $url = trim($arh[$key]); break; } } } } if ($arh === FALSE && function_exists('headers_list')) { foreach (headers_list() as $header) { if (preg_match('/^Location:(.+)$/is', $header, $match)) { $url = trim($match[1]); break; } } } if ($url) { $nosession = strpos($url, session_name() . '=') === FALSE; $url = $this->HypKTaiRender->getRealUrl($url); $url = $this->HypKTaiRender->addSID($url, XOOPS_URL); if (!headers_sent()) { $this->_locationRedirect($url, false); } else { if ($this->HypKTaiRender->vars['ua']['uid'] && $nosession) { $file = XOOPS_ROOT_PATH . '/cache/' . md5($this->HypKTaiRender->vars['ua']['uid'] . XOOPS_DB_PASS) . '.redirect'; $fp = fopen($file, 'w'); fwrite($fp, $url); fclose($fp); } } } } }
/** * Analyze the response header and set "cacheablity" flag * * @return bool true (hook handler */ public static function onRestInPeace() { if (function_exists('apache_response_headers')) { $isCacheable = self::isCacheable(apache_response_headers()); if (is_bool($isCacheable)) { self::setAttribute('cacheable', $isCacheable); } } return true; }
function wp_cache_ob_end() { global $cache_path, $cache_max_time, $file_expired, $file_prefix, $meta_file, $new_cache; global $meta_object, $known_headers; /* Preparing... with PHP5 is straightforward, use headers_list() */ if (function_exists('apache_response_headers')) { $response = apache_response_headers(); $meta_object->headers = array(); foreach ($known_headers as $key) { if (isset($response[$key])) { array_push($meta_object->headers, "{$key}: " . $response[$key]); } } /* Not use 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($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($meta_object->headers, "Last-Modified: {$value}"); } if (!$response['Content-Type']) { $value = "text/html; charset=\"" . get_settings('blog_charset') . "\""; @header("Content-Type: {$value}"); array_push($meta_object->headers, "Content-Type: {$value}"); } } ob_end_clean(); if ($new_cache) { $serial = serialize($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); }
/** * online debug推送到监控中心 * @return void */ public static function sendOnlineDebug() { if (1 === DAGGER_ONLINE_DEBUG && defined("DAGGER_ALARM_DEBUG_API")) { $post = array('pid' => defined('PROJECT_ID') ? PROJECT_ID : 1, 'domain' => $_SERVER['HTTP_HOST'], 'debug_msg' => json_encode(self::$onlineDebugData), 'html' => ob_get_contents(), 'request' => json_encode(apache_request_headers()), 'response' => json_encode(apache_response_headers()), 'client_ip' => BaseModelIp::getClientIp(), 'remote_addr' => $_SERVER['REMOTE_ADDR']); BaseModelHttp::sendRequest(DAGGER_ALARM_DEBUG_API, $post); } }
/** * Construct the class and retrieve the request and response headers. * Will only work on Apache servers. * * @access public * @return void */ public function initialize() { if ($this->_initialized) { return; } $this->initialized(); if (function_exists('apache_response_headers')) { $this->httpHeaders = apache_response_headers() + $this->httpHeaders; } if (function_exists('apache_request_headers')) { $this->httpHeaders = apache_request_headers() + $this->httpHeaders; } }
/** * Try to approximate non ouput buffer bandwidth consumption * Won't take into account output_compression * * @return int Number of bytes */ static function getOtherBandwidth() { $bandwidth = 0; // Add REQUEST params, FILES params, request and response headers to the size of the hit // Use of http_build_query() to approximate HTTP serialization $bandwidth += strlen(http_build_query($_REQUEST)); $bandwidth += strlen(http_build_query($_FILES)); $bandwidth += strlen(http_build_query(apache_request_headers())); $bandwidth += strlen(http_build_query(apache_response_headers())); // Add actual FILES sizes to the size of the hit foreach ($_FILES as $_files) { $_files_size = $_files["size"]; $bandwidth += is_array($_files_size) ? array_sum($_files_size) : $_files_size; } // Add extra bandwidth that may have been declared $bandwidth += self::$extra_bandwidth; return $bandwidth; }
header('Cache-Control: private'); // HTTP/1.1 header('Pragma: public'); // HTTP/1.0 //header('Cache-Control: no-store, no-cache, must-revalidate'); // HTTP/1.1 //header('Cache-Control: post-check=0, pre-check=0', false); // HTTP/1.1 //header('Pragma: no-cache'); // HTTP/1.0 //print $html_header; print "<pre>"; printf("if_modified_since=%s (%s)\n", $if_modified_since, gmdate('r', $if_modified_since)); echo gmdate('D, d M Y H:i:s \\G\\M\\T', time() + 500), "\n"; echo "apache_request_headers()="; $a = apache_request_headers(); ksort($a); print_r($a); echo "apache_response_headers()="; $a = apache_response_headers(); ksort($a); print_r($a); echo "\$_SERVER="; ksort($_SERVER); print_r($_SERVER); ?> <address> $CVSHeader: _freebeer/www/demo/if_modified_since.php,v 1.2 2004/03/07 17:51:33 ross Exp $ </address> </body> </html>
function ob($output) { if ($this->cancel !== false) { return $output; } // PHP5 and objects disappearing before output buffers? wp_cache_init(); // Remember, $wp_object_cache was clobbered in wp-settings.php so we have to repeat this. $this->configure_groups(); // Do not batcache blank pages unless they are HTTP redirects $output = trim($output); if ($output === '' && (!$this->redirect_status || !$this->redirect_location)) { return; } // Construct and save the batcache $cache = array('output' => $output, 'time' => isset($_SERVER['REQUEST_TIME']) ? $_SERVER['REQUEST_TIME'] : time(), 'timer' => $this->timer_stop(false, 3), 'status_header' => $this->status_header, 'redirect_status' => $this->redirect_status, 'redirect_location' => $this->redirect_location, 'version' => $this->url_version); if (function_exists('headers_list')) { foreach (headers_list() as $header) { list($k, $v) = array_map('trim', explode(':', $header, 2)); $cache['headers'][$k] = $v; } } elseif (function_exists('apache_response_headers')) { $cache['headers'] = apache_response_headers(); } if ($cache['headers'] && !empty($this->uncached_headers)) { foreach ($cache['headers'] as $header => $value) { if (in_array(strtolower($header), $this->uncached_headers)) { unset($cache['headers'][$header]); } } } wp_cache_set($this->key, $cache, $this->group, $this->max_age + $this->seconds + 30); // Unlock regeneration wp_cache_delete("{$this->url_key}_genlock", $this->group); if ($this->cache_control) { header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $cache['time']) . ' GMT', true); header("Cache-Control: max-age={$this->max_age}, must-revalidate", false); } if (!empty($this->headers)) { foreach ($this->headers as $k => $v) { if (is_array($v)) { header("{$v[0]}: {$v[1]}", false); } else { header("{$k}: {$v}", true); } } } // Add some debug info just before </head> if ($this->debug) { $tag = "<!--\n\tgenerated in " . $cache['timer'] . " seconds\n\t" . strlen(serialize($cache)) . " bytes batcached for " . $this->max_age . " seconds\n-->\n"; if (false !== ($tag_position = strpos($output, '</head>'))) { $tag = "<!--\n\tgenerated in " . $cache['timer'] . " seconds\n\t" . strlen(serialize($cache)) . " bytes batcached for " . $this->max_age . " seconds\n-->\n"; $output = substr($output, 0, $tag_position) . $tag . substr($output, $tag_position); } } if ($this->debug_header) { header(sprintf("X-batcache: Caching, generated in %ums, expires in %us (%us TTL)", $cache['timer'] * 1000, $this->max_age, $this->max_age), true); } // Pass output to next ob handler return $output; }
private static function getResponseHeaders() { if (function_exists('apache_response_headers')) { return apache_response_headers(); } else { $headers = array(); if (function_exists('headers_list')) { $hList = headers_list(); foreach ($hList as $header) { $header = explode(":", $header); $headers[array_shift($header)] = trim(implode(":", $header)); } } return $headers; } }
protected function collectGlobalEnviroment() { $this->collectGlobalArray('_COOKIE'); $this->collectGlobalArray('_SESSION'); $this->collectGlobalArray('_POST'); $this->collectGlobalArray('_GET'); $this->collectGlobalArray('_FILES'); if (function_exists('apache_request_headers')) { $this->collectArray("Request headers", apache_request_headers()); } if (function_exists('apache_response_headers')) { $this->collectArray("Response headers", apache_response_headers()); } }
/** * Ends the current session, gathering all the available environment data */ public function gather_data($response = '', EurekaProfiler_DB_Adapter $db_adapter = null) { $this->duration = microtime(true) - $this->start; //Request data $this->url = EurekaProfiler_Tools::current_url(); $this->client_ip = EurekaProfiler_Tools::client_ip(); $this->user_agent = $_SERVER['HTTP_USER_AGENT']; $this->get_data = $_GET; $this->post_data = $_POST; $this->cookies = $_COOKIE; if (function_exists('getallheaders')) { $this->request_headers = getallheaders(); } else { $this->request_headers = array(); foreach ($_SERVER as $key => $val) { $extra_headers = array('CONTENT_TYPE', 'CONTENT_LENGTH'); if (strpos($key, 'HTTP_') === 0 || in_array($key, $extra_headers)) { $name = str_replace(array('HTTP_', '_'), array('', '-'), $key); $this->request_headers[$name] = $val; } } } $this->request_headers = array_change_key_case($this->request_headers, CASE_UPPER); //Response data $this->response = $response; $this->response_headers = array(); if (function_exists('apache_response_headers')) { $this->response_headers += apache_response_headers(); } foreach (headers_list() as $header) { list($name, $value) = explode(':', $header, 2); $this->response_headers[$name] = trim($value); } //Runtime data $this->memory_limit = ini_get('memory_limit'); $this->memory_used = memory_get_peak_usage(true); $this->max_execution_time = ini_get('max_execution_time'); //Included files $files = get_included_files(); foreach ($files as $file) { $this->loaded_files[] = new EurekaProfiler_Included(EurekaProfiler_Tools::clean_path($file), filesize($file)); } //Explain queries if (isset($db_adapter)) { foreach ($this->events_of_type('db') as $query) { if (stripos($query->query, 'SELECT') === 0) { $query->explain = $db_adapter->first_row("EXPLAIN {$query->query}"); } else { $query->explain = false; } } } }
/** * 获取apache返回头信息 * <code>Apache::response();</code> * @return array 一维数组 */ public static function response() { return apache_response_headers(); }
$sSessionSupportText = 'Enabled'; } else { $installFlag = false; $sSessionSupportClass = 'bad'; $sSessionSupportText = 'Disabled'; } } //////////////////////////////////////////// // Check charset //////////////////////////////////////////// // Check if AddDefaultCharset is set $e_adc = false; $sapi = php_sapi_name(); if (strpos($sapi, 'apache') !== false || strpos($sapi, 'nsapi') !== false) { flush(); $apache_rheaders = apache_response_headers(); foreach ($apache_rheaders as $h) { if (strpos($h, 'html; charset') !== false) { preg_match('/charset\\s*=\\s*([a-zA-Z0-9- _]+)/', $h, $match); $apache_charset = $match[1]; $e_adc = $apache_charset; } } } $chrval = $e_adc != '' && strtolower($e_adc) != 'utf-8' ? "bad" : "good"; $e_adc = $e_adc . ""; //////////////////////////////////////////// // PHP version check //////////////////////////////////////////// // No install button if Version failes if (version_compare(PHP_VERSION, '5.3.6', '>=')) {
/** * Response Constructor * * @param string|optional $data * Response Data * * @param array|optional $metaData * Response Meta Data */ public function __construct($data = NULL, array $metaData = array()) { parent::__construct(); // Headers Management Object $this->headers = new Headers\ResponseHeaders(); // Extend Object Context to Headers', Cookies and Browser Classes $this->extend(new Invoker($this, $this->headers)); /** * @internal * When dealing with Routed (internal) Requests, no data will * be available because the Front Controller did not send the * Response yet. * * In External Requests, the Response is not sent anyways, * so we condition the buffer length to not hide any output * manually added, like a debugging purposes var_dump() */ if (empty($data) || ob_get_length()) { if (defined('TURBO_MODE') && TURBO_MODE === FALSE) { if (function_exists('apache_response_headers')) { try { $this->headers->addHeader(apache_response_headers()); } catch (FieldsException $e) { /** * @internal * We're silencing the FieldsException in order to not * break the Response Flow * * However, if this Exception is caught, no Response * Headers will be available */ } } else { $headers = headers_list(); foreach ($headers as $data) { list($header, $value) = explode(':', $data, 2); try { $this->headers->addHeader($header, $value); } catch (FieldsException $e) { // Same explanation as above } } } } } else { $this->appendBody($data); if (count($metaData) != 0 && (defined('TURBO_MODE') && TURBO_MODE === FALSE)) { $this->addResponseData($metaData); } } }
<pre> <?php session_start(); echo "[DEBUG] <b>apache</b> headers:\n"; foreach (apache_response_headers() as $name => $value) { echo "{$name}: {$value}\n"; } // Set-Cookie ? echo "\n\n[DEBUG] <b>php</b> headers:\n"; foreach (getallheaders() as $name => $value) { echo "{$name}: {$value}\n"; } ?> </pre>
$fp = fopen('tmp.txt', 'w+'); flock($fp, LOCK_SH); */ $context = stream_context_create(array('http' => array('ignore_errors' => true))); try { $matchIdArr = DB::table('MatchList')->select('MatchList.RegionId', 'MatchList.MatchId')->leftjoin('MatchPlayerSetting', 'MatchList.MatchId', '=', 'MatchPlayerSetting.MatchId')->whereNull('MatchPlayerSetting.MatchId')->orderBy('MatchList.TimeStamp')->distinct()->take(MAX_IMPORT_AMOUNT)->get(); $apiKey = DB::table('APIKey')->select('myKey')->first(); } catch (Exception $e) { echo $e->getMessage(); die; } $cnt = 0; $baseUrl = 'https://na.api.pvp.net/api/lol/' . 'na/v2.2/match/' . '[MatchId]?includeTimeline=true&' . 'api_key=[APIKey]'; foreach ($matchIdArr as $info) { usleep(SLEEP_MICRO_SEC); $responseHeaders = apache_response_headers(); if (array_key_exists("Retry-After", $responseHeaders)) { /* $addSleepSec = $responseHeaders["Retry-After"]; sleep($addSleepSec + 3); */ break; } $matchId = $info->MatchId; $regionId = $info->RegionId; $url = getMatchDetailUrl($baseUrl, $matchId, $apiKey->myKey); $resource = file_get_contents($url, false, $context); /* foreach($http_response_header as $key => $value){ fwrite($fp, $key . ":" . $value . "\n"); }
private static function getResponseHeaders() { $headers = function_exists('apache_response_headers') ? apache_response_headers() : array(); /* * Merge the headers_list into apache_response_headers. * * This is because sometimes things are in one, which are * not present in the other. */ if (function_exists('headers_list')) { $hList = headers_list(); foreach ($hList as $header) { $header = explode(":", $header); $headers[array_shift($header)] = trim(implode(":", $header)); } } return $headers; }
public function refreshResponseHeaders() { // clear old headers self::$aResponseHeaders = array(); // use the apache function, if possible if (function_exists('apache_response_headers')) { self::$aResponseHeaders = apache_response_headers(); } else { $aHeaderList = headers_list(); foreach ($aHeaderList as $sHeader) { $aHeader = explode(':', $sHeader); self::$aResponseHeaders[$aHeader[0]] = trim($aHeader[1]); } } }