当前位置: 首页>>代码示例>>PHP>>正文


PHP HTTP::get_cache_age方法代码示例

本文整理汇总了PHP中HTTP::get_cache_age方法的典型用法代码示例。如果您正苦于以下问题:PHP HTTP::get_cache_age方法的具体用法?PHP HTTP::get_cache_age怎么用?PHP HTTP::get_cache_age使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在HTTP的用法示例。


在下文中一共展示了HTTP::get_cache_age方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: publishPages

 /**
  * Uses {@link Director::test()} to perform in-memory HTTP requests
  * on the passed-in URLs.
  * 
  * @param  array $urls Relative URLs 
  * @return array Result, keyed by URL. Keys: 
  *               - "statuscode": The HTTP status code
  *               - "redirect": A redirect location (if applicable)
  *               - "path": The filesystem path where the cache has been written
  */
 public function publishPages($urls)
 {
     $result = array();
     //nest the config so we can make changes to the config and revert easily
     Config::nest();
     // Do we need to map these?
     // Detect a numerically indexed arrays
     if (is_numeric(join('', array_keys($urls)))) {
         $urls = $this->urlsToPaths($urls);
     }
     // This can be quite memory hungry and time-consuming
     // @todo - Make a more memory efficient publisher
     increase_time_limit_to();
     increase_memory_limit_to();
     // Set the appropriate theme for this publication batch.
     // This may have been set explicitly via StaticPublisher::static_publisher_theme,
     // or we can use the last non-null theme.
     $customTheme = Config::inst()->get('StaticPublisher', 'static_publisher_theme');
     if ($customTheme) {
         Config::inst()->update('SSViewer', 'theme', $customTheme);
     }
     // Ensure that the theme that is set gets used.
     Config::inst()->update('SSViewer', 'theme_enabled', true);
     $staticBaseUrl = Config::inst()->get('FilesystemPublisher', 'static_base_url');
     if ($staticBaseUrl) {
         Config::inst()->update('Director', 'alternate_base_url', $staticBaseUrl);
     }
     if ($this->fileExtension == 'php') {
         Config::inst()->update('SSViewer', 'rewrite_hash_links', 'php');
     }
     if (Config::inst()->get('StaticPublisher', 'echo_progress')) {
         echo $this->class . ": Publishing to " . $staticBaseUrl . "\n";
     }
     $files = array();
     $i = 0;
     $totalURLs = sizeof($urls);
     foreach ($urls as $url => $path) {
         $origUrl = $url;
         $result[$origUrl] = array('statuscode' => null, 'redirect' => null, 'path' => null);
         $i++;
         if ($url && !is_string($url)) {
             user_error("Bad url:" . var_export($url, true), E_USER_WARNING);
             continue;
         }
         if (Config::inst()->get('StaticPublisher', 'echo_progress')) {
             echo " * Publishing page {$i}/{$totalURLs}: {$url}\n";
             flush();
         }
         Requirements::clear();
         if ($url == "") {
             $url = "/";
         }
         if (Director::is_relative_url($url)) {
             $url = Director::absoluteURL($url);
         }
         $response = Director::test(str_replace('+', ' ', $url));
         if (!$response) {
             continue;
         }
         if ($response) {
             $result[$origUrl]['statuscode'] = $response->getStatusCode();
         }
         Requirements::clear();
         singleton('DataObject')->flushCache();
         // Check for ErrorPages generating output - we want to handle this in a special way below.
         $isErrorPage = false;
         $pageObject = null;
         if ($response && is_object($response) && (int) $response->getStatusCode() >= 400) {
             $pageObject = SiteTree::get_by_link($url);
             if ($pageObject && $pageObject instanceof ErrorPage) {
                 $isErrorPage = true;
             }
         }
         // Skip any responses with a 404 status code unless it's the ErrorPage itself.
         if (!$isErrorPage && is_object($response) && $response->getStatusCode() == '404') {
             continue;
         }
         // Generate file content
         // PHP file caching will generate a simple script from a template
         if ($this->fileExtension == 'php') {
             if (is_object($response)) {
                 if ($response->getStatusCode() == '301' || $response->getStatusCode() == '302') {
                     $content = $this->generatePHPCacheRedirection($response->getHeader('Location'));
                 } else {
                     $content = $this->generatePHPCacheFile($response->getBody(), HTTP::get_cache_age(), date('Y-m-d H:i:s'), $response->getHeader('Content-Type'));
                 }
             } else {
                 $content = $this->generatePHPCacheFile($response . '', HTTP::get_cache_age(), date('Y-m-d H:i:s'), $response->getHeader('Content-Type'));
             }
             // HTML file caching generally just creates a simple file
//.........这里部分代码省略.........
开发者ID:briceburg,项目名称:silverstripe-staticpublisher,代码行数:101,代码来源:FilesystemPublisher.php

示例2: publishPages

 function publishPages($urls)
 {
     // Do we need to map these?
     // Detect a numerically indexed arrays
     if (is_numeric(join('', array_keys($urls)))) {
         $urls = $this->urlsToPaths($urls);
     }
     // This can be quite memory hungry and time-consuming
     // @todo - Make a more memory efficient publisher
     increase_time_limit_to();
     increase_memory_limit_to();
     // Set the appropriate theme for this publication batch.
     // This may have been set explicitly via StaticPublisher::static_publisher_theme,
     // or we can use the last non-null theme.
     if (!StaticPublisher::static_publisher_theme()) {
         SSViewer::set_theme(SSViewer::current_custom_theme());
     } else {
         SSViewer::set_theme(StaticPublisher::static_publisher_theme());
     }
     $currentBaseURL = Director::baseURL();
     if (self::$static_base_url) {
         Director::setBaseURL(self::$static_base_url);
     }
     if ($this->fileExtension == 'php') {
         SSViewer::setOption('rewriteHashlinks', 'php');
     }
     if (StaticPublisher::echo_progress()) {
         echo $this->class . ": Publishing to " . self::$static_base_url . "\n";
     }
     $files = array();
     $i = 0;
     $totalURLs = sizeof($urls);
     foreach ($urls as $url => $path) {
         if (self::$static_base_url) {
             Director::setBaseURL(self::$static_base_url);
         }
         $i++;
         if ($url && !is_string($url)) {
             user_error("Bad url:" . var_export($url, true), E_USER_WARNING);
             continue;
         }
         if (StaticPublisher::echo_progress()) {
             echo " * Publishing page {$i}/{$totalURLs}: {$url}\n";
             flush();
         }
         Requirements::clear();
         if ($url == "") {
             $url = "/";
         }
         if (Director::is_relative_url($url)) {
             $url = Director::absoluteURL($url);
         }
         $response = Director::test(str_replace('+', ' ', $url));
         Requirements::clear();
         singleton('DataObject')->flushCache();
         //skip any responses with a 404 status code. We don't want to turn those into statically cached pages
         if (!$response || $response->getStatusCode() == '404') {
             continue;
         }
         // Generate file content
         // PHP file caching will generate a simple script from a template
         if ($this->fileExtension == 'php') {
             if (is_object($response)) {
                 if ($response->getStatusCode() == '301' || $response->getStatusCode() == '302') {
                     $content = $this->generatePHPCacheRedirection($response->getHeader('Location'));
                 } else {
                     $content = $this->generatePHPCacheFile($response->getBody(), HTTP::get_cache_age(), date('Y-m-d H:i:s'));
                 }
             } else {
                 $content = $this->generatePHPCacheFile($response . '', HTTP::get_cache_age(), date('Y-m-d H:i:s'));
             }
             // HTML file caching generally just creates a simple file
         } else {
             if (is_object($response)) {
                 if ($response->getStatusCode() == '301' || $response->getStatusCode() == '302') {
                     $absoluteURL = Director::absoluteURL($response->getHeader('Location'));
                     $content = "<meta http-equiv=\"refresh\" content=\"2; URL={$absoluteURL}\">";
                 } else {
                     $content = $response->getBody();
                 }
             } else {
                 $content = $response . '';
             }
         }
         $files[] = array('Content' => $content, 'Folder' => dirname($path) . '/', 'Filename' => basename($path));
         // Add externals
         /*
         			$externals = $this->externalReferencesFor($content);
         			if($externals) foreach($externals as $external) {
         				// Skip absolute URLs
         				if(preg_match('/^[a-zA-Z]+:\/\//', $external)) continue;
         				// Drop querystring parameters
         				$external = strtok($external, '?');
         				
         				if(file_exists("../" . $external)) {
         					// Break into folder and filename
         					if(preg_match('/^(.*\/)([^\/]+)$/', $external, $matches)) {
         						$files[$external] = array(
         							"Copy" => "../$external",
         							"Folder" => $matches[1],
//.........这里部分代码省略.........
开发者ID:comperio,项目名称:silverstripe-cms,代码行数:101,代码来源:FilesystemPublisher.php

示例3: publishPages

 /**
  * Uses {@link Director::test()} to perform in-memory HTTP requests
  * on the passed-in URLs.
  * 
  * @param  array $urls Relative URLs 
  * @return array Result, keyed by URL. Keys: 
  *               - "statuscode": The HTTP status code
  *               - "redirect": A redirect location (if applicable)
  *               - "path": The filesystem path where the cache has been written
  */
 public function publishPages($urls)
 {
     $result = array();
     // Do we need to map these?
     // Detect a numerically indexed arrays
     if (is_numeric(join('', array_keys($urls)))) {
         $urls = $this->urlsToPaths($urls);
     }
     // This can be quite memory hungry and time-consuming
     // @todo - Make a more memory efficient publisher
     increase_time_limit_to();
     increase_memory_limit_to();
     Config::inst()->nest();
     // Set the appropriate theme for this publication batch.
     // This may have been set explicitly via StaticPublisher::static_publisher_theme,
     // or we can use the last non-null theme.
     $customTheme = Config::inst()->get('FilesystemPublisher', 'static_publisher_theme');
     if ($customTheme) {
         Config::inst()->update('SSViewer', 'theme', $customTheme);
     }
     // Ensure that the theme that is set gets used.
     Config::inst()->update('SSViewer', 'theme_enabled', true);
     $currentBaseURL = Director::baseURL();
     $staticBaseUrl = Config::inst()->get('FilesystemPublisher', 'static_base_url');
     if ($this->fileExtension == 'php') {
         Config::inst()->update('SSViewer', 'rewrite_hash_links', 'php');
     }
     if (Config::inst()->get('FilesystemPublisher', 'echo_progress')) {
         echo $this->class . ": Publishing to " . $staticBaseUrl . "\n";
     }
     $files = array();
     $i = 0;
     $totalURLs = sizeof($urls);
     foreach ($urls as $url => $path) {
         $origUrl = $url;
         $result[$origUrl] = array('statuscode' => null, 'redirect' => null, 'path' => null);
         $i++;
         if ($url && !is_string($url)) {
             user_error("Bad url:" . var_export($url, true), E_USER_WARNING);
             continue;
         }
         if (Config::inst()->get('FilesystemPublisher', 'echo_progress')) {
             echo " * Publishing page {$i}/{$totalURLs}: {$url}\n";
             flush();
         }
         Requirements::clear();
         if ($url == "") {
             $url = "/";
         }
         if (Director::is_relative_url($url)) {
             $url = Director::absoluteURL($url);
         }
         $sanitizedURL = URLArrayObject::sanitize_url($url);
         $response = Director::test(str_replace('+', ' ', $sanitizedURL));
         // Prevent empty static cache files from being written
         if (is_object($response) && !$response->getBody()) {
             SS_Log::log(new Exception('Prevented blank static cache page write for: ' . $path), SS_Log::NOTICE);
             continue;
         }
         if (!$response) {
             continue;
         }
         if ($response) {
             $result[$origUrl]['statuscode'] = $response->getStatusCode();
         }
         Requirements::clear();
         singleton('DataObject')->flushCache();
         // Check for ErrorPages generating output - we want to handle this in a special way below.
         $isErrorPage = false;
         $pageObject = null;
         if ($response && is_object($response) && (int) $response->getStatusCode() >= 400) {
             $obj = $this->owner->getUrlArrayObject()->getObject($url);
             if ($obj && $obj instanceof ErrorPage) {
                 $isErrorPage = true;
             }
         }
         // Skip any responses with a 404 status code unless it's the ErrorPage itself.
         if (!$isErrorPage && is_object($response) && $response->getStatusCode() == '404') {
             continue;
         }
         // Generate file content.
         // PHP file caching will generate a simple script from a template
         if ($this->fileExtension == 'php') {
             if (is_object($response)) {
                 if ($response->getStatusCode() == '301' || $response->getStatusCode() == '302') {
                     $content = $this->generatePHPCacheRedirection($response->getHeader('Location'));
                 } else {
                     $content = $this->generatePHPCacheFile($response->getBody(), HTTP::get_cache_age(), date('Y-m-d H:i:s'), $response->getHeader('Content-Type'));
                 }
             } else {
//.........这里部分代码省略.........
开发者ID:spark-green,项目名称:silverstripe-staticpublishqueue,代码行数:101,代码来源:FilesystemPublisher.php

示例4: publishUrls


//.........这里部分代码省略.........
     $i = 0;
     $totalURLs = sizeof($urls);
     $cache = $this->getCache();
     if (!defined('PROXY_CACHE_GENERATING')) {
         define('PROXY_CACHE_GENERATING', true);
     }
     foreach ($urls as $url => $path) {
         // work around bug introduced in ss3 whereby top level /bathroom.html would be changed to ./bathroom.html
         $path = ltrim($path, './');
         $url = rtrim($url, '/');
         // TODO: Detect the scheme + host URL from the URL's absolute path
         // and set that as the base URL appropriately
         $baseUrlSrc = $this->staticBaseUrl ? $this->staticBaseUrl : $url;
         $urlBits = parse_url($baseUrlSrc);
         if (isset($urlBits['scheme']) && isset($urlBits['host'])) {
             // now see if there's a host mapping
             // we want to set the base URL correctly
             Config::inst()->update('Director', 'alternate_base_url', $urlBits['scheme'] . '://' . $urlBits['host'] . '/');
         }
         $i++;
         if ($url && !is_string($url)) {
             user_error("Bad url:" . var_export($url, true), E_USER_WARNING);
             continue;
         }
         Requirements::clear();
         if (strrpos($url, '/home') == strlen($url) - 5) {
             $url = substr($url, 0, strlen($url) - 5);
         }
         if ($url == "" || $url == 'home') {
             $url = "/";
         }
         if (Director::is_relative_url($url)) {
             $url = Director::absoluteURL($url);
         }
         $stage = Versioned::current_stage();
         Versioned::reading_stage('Live');
         $GLOBALS[self::CACHE_PUBLISH] = 1;
         Config::inst()->update('SSViewer', 'theme_enabled', true);
         if (class_exists('Multisites')) {
             Multisites::inst()->resetCurrentSite();
         }
         $response = Director::test(str_replace('+', ' ', $url));
         Config::inst()->update('SSViewer', 'theme_enabled', false);
         unset($GLOBALS[self::CACHE_PUBLISH]);
         Versioned::reading_stage($stage);
         Requirements::clear();
         singleton('DataObject')->flushCache();
         $contentType = null;
         // Generate file content
         if (is_object($response)) {
             if ($response->getStatusCode() == '301' || $response->getStatusCode() == '302') {
                 $absoluteURL = Director::absoluteURL($response->getHeader('Location'));
                 $content = null;
             } else {
                 $content = $response->getBody();
                 $type = $response->getHeader('Content-type');
                 $contentType = $type ? $type : $contentType;
             }
         } else {
             $content = $response . '';
         }
         if (!$content) {
             continue;
         }
         if (isset($urlBits['host'])) {
             $domain = $urlBits['host'];
         }
         if ($domain && !$keyPrefix) {
             $keyPrefix = $domain;
         }
         $path = trim($path, '/');
         if ($path == 'home') {
             $path = '';
         }
         $data = new stdClass();
         $data->Content = $content;
         $data->LastModified = date('Y-m-d H:i:s');
         $cacheAge = SiteConfig::current_site_config()->CacheAge;
         if ($cacheAge) {
             $data->Age = $cacheAge;
         } else {
             $data->Age = HTTP::get_cache_age();
         }
         if (!empty($contentType)) {
             $data->ContentType = $contentType;
         }
         $key = $keyPrefix . '/' . $path;
         $cache->store($key, $data);
         if ($domain && isset($PROXY_CACHE_HOSTMAP) && isset($PROXY_CACHE_HOSTMAP[$domain])) {
             $hosts = $PROXY_CACHE_HOSTMAP[$domain];
             foreach ($hosts as $otherDomain) {
                 $key = $otherDomain . '/' . $path;
                 $storeData = clone $data;
                 $storeData->Content = str_replace($domain, $otherDomain, $storeData->Content);
                 $cache->store($key, $storeData);
             }
         }
     }
     Director::setBaseURL($currentBaseURL);
 }
开发者ID:helpfulrobot,项目名称:silverstripe-australia-simplecache,代码行数:101,代码来源:SimpleCachePublisher.php


注:本文中的HTTP::get_cache_age方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。