/**
  * save data to disk. throws an exception if writing failed and DEBUG>0
  */
 protected static function saveData()
 {
     kataMakeTmpPath('cache');
     $data = '<? $data=' . var_export(self::$dataArr, true) . ';';
     if (false === file_put_contents(KATATMP . 'cache' . DS . CACHE_IDENTIFIER . '-kataRegistry', $data)) {
         if (DEBUG > 0) {
             throw new Exception('katareg: cannot write data. wrong rights?');
         }
         return false;
     }
     return true;
 }
Ejemplo n.º 2
0
 /**
  * set first store/read-method as default
  */
 function initialize()
 {
     if ($this->isInitialized) {
         return;
     }
     $this->results = array();
     kataMakeTmpPath('cache');
     if (defined('CACHE_USEMETHOD')) {
         $this->method = CACHE_USEMETHOD;
         $this->defaultMethod = CACHE_USEMETHOD;
         $this->isInitialized = true;
         return;
     }
     if (defined('MEMCACHED_SERVERS') && '' != MEMCACHED_SERVERS && class_exists('Memcached')) {
         $this->method = self::CM_MEMCACHED;
         $this->defaultMethod = self::CM_MEMCACHED;
         $this->initMemcached(true);
         $this->isInitialized = true;
         return;
     }
     if (defined('MEMCACHED_SERVERS') && '' != MEMCACHED_SERVERS && class_exists('Memcache')) {
         $this->method = self::CM_MEMCACHE;
         $this->defaultMethod = self::CM_MEMCACHE;
         $this->initMemcached();
         $this->isInitialized = true;
         return;
     }
     if (function_exists('apc_fetch')) {
         if (CLI != 1 && ini_get('apc.enabled') || CLI == 1 && ini_get('apc.enable_cli')) {
             $this->method = self::CM_APC;
             $this->defaultMethod = self::CM_APC;
             $this->isInitialized = true;
             return;
         }
     }
     if (function_exists('xcache_get')) {
         $this->method = self::CM_XCACHE;
         $this->defaultMethod = self::CM_XCACHE;
         $this->isInitialized = true;
         return;
     }
     if (function_exists('eaccelerator_get') && ini_get('eaccelerator.enable')) {
         $this->method = self::CM_EACC;
         $this->defaultMethod = self::CM_EACC;
         $this->isInitialized = true;
         return;
     }
     $this->method = self::CM_FILE;
     $this->defaultMethod = self::CM_FILE;
     $this->isInitialized = true;
 }
 /**
  * connect to the database
  */
 function connect()
 {
     kataMakeTmpPath('sqlite');
     $db = $this->dbconfig['database'];
     if ($db[0] != DS) {
         $db = KATATMP . 'sqlite' . DS . $db;
     }
     $this->link = new SQLite3($db, 0750);
     if (!$this->link) {
         throw new DatabaseConnectException("Could not open database " . $db);
     }
     if (!empty($this->dbconfig['encoding'])) {
         $this->setEncoding($this->dbconfig['encoding']);
     }
 }
Ejemplo n.º 4
0
/**
 * write a string to the log in KATATMP/logs. 
 * if DEBUG<0 logentries that have $where==0 are not written.
 *
 * @param string $what string to write to the log
 * @param int $where log-level to log (default: 0)
 */
function writeLog($what, $where = 2)
{
    $logname = 'error';
    if (is_numeric($where)) {
        if (DEBUG < 0 && 2 == $where) {
            return;
        }
        if (2 == $where) {
            $logname = 'debug';
        } elseif (0 == $where) {
            $logname = 'panic';
        }
    } else {
        $logname = basename($where);
    }
    kataMakeTmpPath('logs');
    $h = fopen(KATATMP . 'logs' . DS . $logname . '.log', 'a');
    if ($h) {
        fwrite($h, date('d.m.Y H:i:s ') . $what . "\n");
        fclose($h);
    }
}
Ejemplo n.º 5
0
 /**
  * generate individual tags if DEBUG>0 OR pack all files into a single one, chache the file,
  * replace with a single tag that points to a url that reads the cached+joined file
  *
  * Minifies only in DEBUG <= 0
  *
  * all .c.css files are computed
  * 
  * @param array $files individual files, relative to webroot
  * @param string $target js/css
  * @param string $tagFormat printf-able string of the individual tag
  * @param bool $cacheAndMinify if we should join+compress+cache given target
  * @param bool $rtl include rtl-stuff instead of ltr-stuff
  */
 private function joinFiles($files, $target, $tagFormat, $cacheAndMinify, $rtl = false)
 {
     // debugging? just return individual tags
     if (!$cacheAndMinify) {
         $html = '';
         foreach ($files as $file) {
             if ('.c.css' == substr($file, -6, 6)) {
                 $html .= $this->joinFiles(array($file), $target, $tagFormat, true, $rtl);
             } else {
                 $html .= sprintf($tagFormat, $this->url($target . '/' . $file));
             }
         }
         return $html;
     }
     kataMakeTmpPath('cache');
     // cachefile exists and is young enough?
     $slug = md5(implode($files, ',') . (defined('VERSION') ? VERSION : '') . ($rtl ? 'rtl' : ''));
     $cacheFile = KATATMP . 'cache' . DS . $target . '.cache.' . $slug;
     if (file_exists($cacheFile) && time() - filemtime($cacheFile) < HOUR && DEBUG <= 0) {
         return sprintf($tagFormat, $this->url($target . '/_cache-' . $slug));
     }
     // build cachefile
     $content = '';
     foreach ($files as $file) {
         $x = strpos($file, '?');
         if ($x > 0) {
             $file = substr($file, 0, $x);
         }
         $txt = file_get_contents(WEBROOT . $target . DS . $file);
         if (false === $txt) {
             throw new Exception("html: cant find {$target}-file '{$file}'");
         }
         if ('.c.css' == substr($file, -6, 6)) {
             $txt = $this->filterCss($txt, $rtl);
         }
         $content .= $txt . "\n\n\n\n\n\n";
     }
     $ignoreMinify = DEBUG > 0;
     if ('css' == $target && !$ignoreMinify) {
         $miniUtil = getUtil('Minify');
         $content = $miniUtil->css($content);
     }
     if ('js' == $target && !$ignoreMinify) {
         $miniUtil = getUtil('Minify');
         $content = $miniUtil->js($content);
     }
     file_put_contents($cacheFile, $content);
     return sprintf($tagFormat, $this->url($target . '/_cache-' . $slug . (DEBUG > 0 ? '?' . time() : '')));
 }
Ejemplo n.º 6
0
 /**
  * setup up session directory
  */
 function __construct()
 {
     kataMakeTmpPath('sessions');
 }
Ejemplo n.º 7
0
 protected function initSessionParams()
 {
     ini_set('url_rewriter.tags', '');
     ini_set('session.use_cookies', 1);
     ini_set('session.name', SESSION_COOKIE);
     ini_set('session.hash_bits_per_character', 6);
     ini_set('session_cache_limiter', 'nocache');
     ini_set('session.cookie_path', $this->path);
     ini_set('session.cookie_domain', $this->domain);
     ini_set('session.cookie_lifetime', SESSION_TIMEOUT);
     ini_set('session.gc_maxlifetime', SESSION_TIMEOUT);
     if (!defined('SESSION_SYSPATH') || !SESSION_SYSPATH) {
         kataMakeTmpPath('sessions');
         ini_set('session.save_path', KATATMP . 'sessions');
     }
 }
Ejemplo n.º 8
0
 public function write($topic, $msg)
 {
     $this->initialize();
     switch ($this->method) {
         case null:
             throw new Exception('You have to setMethod() first');
             break;
         case self::QM_MSGQUEUE:
             $error = 0;
             msg_send($this->queueRes, $topic, $msg, true, false, &$error);
             return 0 == $error;
             break;
         case self::QM_ZEROMQ:
             break;
         case self::QM_LIBEVENT:
             break;
         case self::QM_FILESOCKET:
             $socket = @socket_create(AF_UNIX, SOCK_STREAM, 0);
             if (!$socket) {
                 return false;
             }
             if (!@socket_connect($socket, $this->queuePath . 'queue.' . $this->queueId)) {
                 $err = socket_last_error();
                 if (ECONNREFUSED == $err) {
                     throw new Exception('Connection error. Queue-server (service.php) not running?');
                 }
             }
             if (false === socket_write($socket, json_encode(array('topic' => $topic)))) {
                 return false;
             }
             //TODO while() read
             socket_close($socket);
             break;
         case self::QM_FILESYS:
             $topic = urlencode($topic);
             kataMakeTmpPath('queue' . DS . $topic);
             $handle = fopen($this->queuePath . DS . $topic . DS . 'q.' . microtime(true), 'xb');
             if (!$handle) {
                 return false;
             }
             fwrite($handle, serialize($msg));
             fclose($handle);
             return true;
             break;
     }
     //switch
 }