public static function set($key, $value, $time = 60) { $data = new \Model\Cache(); $data->key = $key; $data->data = $value; $data->expiredat = date("Y-m-d H:i:s", time() + $time); $data->save(); }
public static function request($conf, $method, $params) { $apiKey = $conf->getOption('app', 'lastfmapikey'); $qparams = http_build_query($params); $q = self::$root . "?method={$method}&format=json&api_key={$apiKey}&{$qparams}"; $cacheKey = "lastfm_" . sha1($q) . ".json"; $data = \Model\Cache::find('one', array('conditions' => array('`expiredAt` > ? AND `key` = ?', time(), $cacheKey))); if (!$data) { $resp = file_get_contents($q); $data = new \Model\Cache(); $data->key = $cacheKey; $data->data = $resp; $data->expiredat = date("Y-m-d H:i:s", time() + $conf->getOption('cache', 'artists')); $data->save(); } $data = json_decode($data->data); return $data; }
<?php use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; $app->get('/part/{file}', function ($file) use($app) { $avparts = array("menu"); if (!in_array($file, $avparts)) { return new Response("WTF?"); } return $app['view']->render(null, "part/{$file}.phtml"); }); $app->get('/cc', function () use($app) { $cache = Model\Cache::find('all'); foreach ($cache as $c) { $c->delete(); } foreach (glob(ROOT . "/assets/*") as $file) { unlink($file); } return new Response("Cache cleaned"); }); $app->get('/plslist', function () use($app) { $pls = Model\Pl::find_all_by_userid($app['user']::get('id')); return $app['view']->render(null, "part/plslist.phtml", array('pls' => $pls)); });
/** * @param $revision * @param $type * @return array */ public static function executeScript($revision, $type) { $script = PIMCORE_SYSTEM_TEMP_DIRECTORY . "/update/" . $revision . "/scripts/" . $type . ".php"; $maxExecutionTime = 900; @ini_set("max_execution_time", $maxExecutionTime); set_time_limit($maxExecutionTime); Model\Cache::disable(); // it's important to disable the cache here eg. db-schemas, ... if (is_file($script)) { ob_start(); try { if (!self::$dryRun) { include $script; } } catch (\Exception $e) { \Logger::error($e); } $outputMessage = ob_get_clean(); } return array("message" => $outputMessage, "success" => true); }
<?php // РЕКЛАМА!!!!!!!!!!!!!! + ДОНЕЙТ!!!!!!!!!!!!!!!1 // Powered by: // - Silex (http://silex.sensiolabs.org), // - PHPActiveRecord (http://phpactiverecord.org), // - OpenPlayer (https://github.com/uavn/openplayer), // - Pagerfanta (https://github.com/whiteoctober/Pagerfanta) session_start(); date_default_timezone_set('Europe/Moscow'); define('ROOT', __DIR__); require_once ROOT . '/silex.phar'; require_once ROOT . '/autoload.php'; require_once ROOT . '/helpers.php'; require_once 'phar://' . __DIR__ . '/silex.phar/autoload.php'; $app = new Silex\Application(); $app['debug'] = 'localhost' == $_SERVER['HTTP_HOST']; ini_set("display_errors", $app['debug'] ? "on" : "off"); require_once ROOT . '/services.php'; require_once ROOT . '/controllers.php'; $app->run(); // clearing old cache $cache = Model\Cache::find('all', array('conditions' => array('expiredAt < ?', date("Y-m-d H:i:s")))); foreach ($cache as $c) { $c->delete(); }