[ كلاس ] Traidnt.Net : لإنشاء cache السلام عليكم ورحمة الله وبركاتة .. كلاس قمت ببرمجتة لكي يقوم بإنشاء cache لملفات السكربت الكلاس كامل : رمز PHP: <span style="color: #000000">class CacheC { public function __construct($dirCache, $typeFiles, $typeFilesCache, $timeToDeleteCache) { $this->dirCache = $dirCache; $this->typeFiles = $typeFiles; $this->typeFilesCache = $typeFilesCache; $this->timeToDeleteCache = $timeToDeleteCache; if(!file_exists($this->dirCache)) { $this->showError('Dir '.$this->dirCache.' Not Found'); } } public function existsFile($filename) { $filename = $filename.$this->typeFiles; return file_exists($filename) ? true : false; } public function cacheExists($filename) { $filename = $this->dirCache.$filename.$this->typeFilesCache; return file_exists($filename) ? true : false; } public function createCache($files) { if(is_array($files)) { foreach ($files as $file) { $this->createCache2($file); } } else { $this->createCache2($files); } } public function createCache2($filename) { if(!$this->existsFile($filename)) { $this->showError('File Not Found'); } if($this->cacheExists($filename)) { return false; } $file = $filename.$this->typeFiles; $fileCache = $this->dirCache.$filename.$this->typeFilesCache; $x = file_get_contents('http://'.$this->getDomain().$file, true); file_put_contents($fileCache, $x); } public function getCache($files) { if(is_array($files)) { foreach ($files as $file) { $this->getCache2($file); } } else { $this->getCache2($files); } } public function getCache2($file) { if($this->cacheExists($file)) { $filenax = $this->dirCache.$file.$this->typeFilesCache; $time = filemtime($filenax); $time2 = $time+$this->timeToDeleteCache; if(time() >= $time2) { unlink($filenax); } else { require_once $filenax; } } } public function getDomain() { $surl = $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; $surl = preg_replace( "/^(www\\.)/", "", $surl ); $arr = explode( "/", $surl ); $count = sizeof( $arr ) - 1; if ( 0 <span style="color: #007700">$cache = new CacheC('html/', '.php', '.html', 60); تشغيل الكلاس html = الملف الخاص بتخزين ملفات الكاش .php = صيغة الملفات .html = صيغة الملفات للكاش 60 = عدد الثواني لتجديد ملفات الكاش لإستدعاء الكاش رمز PHP: $cache->getCache(['index', 'login']); او رمز PHP: $cache->getCache('index'); لإنشاء الكلاس رمز PHP: $cache->createCache(['index', 'login']); او رمز PHP: $cache->createCache('index'); ارائكم في الكلاس + اتمنى تستفيدو منه :) بالتوفيق . |
الساعة الآن 08:06 PM |
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.5.2 TranZ By
Almuhajir