Здравейте,
Тъй като мой сайт се оказа много тежък и постоянно генерира ресурси, а и лагва, ми хрумна идеята да използвам кеш. То всъщност е един прост php код, който ще ви споделя тук:
Праскаш го в страницата и забравяш. Въпросът ми е, дали Гугъл се сърди на подобни изпълнения? То в края на краищата се кешира техният си код, не конкретната реклама, така че не вярвам... но все пак да питам. Плюс това рекламите си се сменят, въпреки четенето от кеша ![Wink ;) ;)](data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7)
Та... просто реших да попитам![Wink ;) ;)](data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7)
.wysiwyg { background-attachment: scroll; background-repeat: repeat; background-position: 0% 0%; background-color: #f5f5ff; background-image: none; color: #000000; font-family: Verdana, Arial, Helvetica, Arial; font-style: normal; font-variant: normal; font-weight: 400; font-size: 10pt; line-height: normal } p { margin: 0px; }.wysiwyg { background-attachment: scroll; background-repeat: repeat; background-position: 0% 0%; background-color: #f5f5ff; background-image: none; color: #000000; font-family: Verdana, Arial, Helvetica, Arial; font-style: normal; font-variant: normal; font-weight: 400; font-size: 10pt; line-height: normal } p { margin: 0px; }.wysiwyg { background-attachment: scroll; background-repeat: repeat; background-position: 0% 0%; background-color: #f5f5ff; background-image: none; color: #000000; font-family: Verdana, Arial, Helvetica, Arial; font-style: normal; font-variant: normal; font-weight: 400; font-size: 10pt; line-height: normal } p { margin: 0px; }
Тъй като мой сайт се оказа много тежък и постоянно генерира ресурси, а и лагва, ми хрумна идеята да използвам кеш. То всъщност е един прост php код, който ще ви споделя тук:
Код:
<?php
**// Define cache directory - change to your own directory
**define ('cache_dir', '/home/your_username/public_html/tmp/');
**// How long is data in cache valid - in hours
**define ('cache_time', 1);
**function cache_page ($content) {
**// Get current URL
**$url = get_url();
**// Create a unique filename out of our URL
**$filename = md5($url) . '.html';
**// Create data string
**$data = mktime() . '|' . $content;
**// Write file
**$f = fopen(cache_dir . $filename, 'w');
**fwrite($f, $data);
**fclose($f);
**return $content;
**}
**function get_url () {
**if (!isset($_SERVER['REQUEST_URI'])) {
**$url = $_SERVER['REQUEST_URI'];
**} else {
**$url = $_SERVER['SCRIPT_NAME'];
**$url .= (!empty($_SERVER['QUERY_STRING'])) ? '?' . $_SERVER['QUERY_STRING'] : '';
**}
**return $url;
**}
**function display_cache () {
**// Get current URL
**$url = get_url();
**// Get filename of the current URL
**$filename = md5($url) . '.html';
**$file = cache_dir . $filename;
**// Cache exists?
**if (!file_exists($file)) {
**// No cache, exit function
**return false;
**}
**// Get data
**$f = fopen($file, 'r');
**$data = fread($f, filesize($file));
**fclose($f);
**// Split timestamp and content
**$data = explode('|', $data, 2);
**// Is data valid?
**if (count($data) != 2 OR !is_numeric($data['0'])) {
**return false;
**}
**// Check if cache isn't too old
**// If current time - cachetime is bigger than cached data
**// Then not valid
**if (mktime()-(cache_time*60*60) > $data['0']) {
**return false;
**}
**// Cache is valid, display it, and end page
**echo $data['1'];
**die();
**}
**// Display cache (if any)
**display_cache();
**// Enable output buffering, with our caching callback
**ob_start ('cache_page');
**?>
**
Та... просто реших да попитам
.wysiwyg { background-attachment: scroll; background-repeat: repeat; background-position: 0% 0%; background-color: #f5f5ff; background-image: none; color: #000000; font-family: Verdana, Arial, Helvetica, Arial; font-style: normal; font-variant: normal; font-weight: 400; font-size: 10pt; line-height: normal } p { margin: 0px; }.wysiwyg { background-attachment: scroll; background-repeat: repeat; background-position: 0% 0%; background-color: #f5f5ff; background-image: none; color: #000000; font-family: Verdana, Arial, Helvetica, Arial; font-style: normal; font-variant: normal; font-weight: 400; font-size: 10pt; line-height: normal } p { margin: 0px; }.wysiwyg { background-attachment: scroll; background-repeat: repeat; background-position: 0% 0%; background-color: #f5f5ff; background-image: none; color: #000000; font-family: Verdana, Arial, Helvetica, Arial; font-style: normal; font-variant: normal; font-weight: 400; font-size: 10pt; line-height: normal } p { margin: 0px; }