Jump to content

Darghon

Members
  • Posts

    83
  • Joined

  • Last visited

Everything posted by Darghon

  1. Hello all, i'm attempting to implement i18n into my project. so I read some tutorials, copied some code and eventually made the following: /** * applyMultiLingual uses the gettext module from PHP to support multilingual * @param Array $settings */ private static function applyMultiLingual($settings){ /* init global config */ bindtextdomain(self::$project_name,Config::path('i18n')); bind_textdomain_codeset(self::$project_name, 'UTF-8'); textdomain(self::$project_name); if(!array_key_exists('enabled', $settings) || $settings['enabled'] == false){ //initiate default (english) putenv("LC_MESSAGES=en_EN"); setlocale(LC_MESSAGES,'en_EN'); } else{ if(Session::language() === null){ //initiate custom if($settings['default'] == 'auto'){ locale::acceptFromHttp($header); } else{ putenv("LC_MESSAGES=".$settings['default']);setlocale(LC_MESSAGES,$settings['default']); } } else{ putenv("LC_MESSAGES=".Session::language()); setlocale(LC_MESSAGES,Session::language()); } } } The code is (imo) pretty readable, so it sets the textdomain to "project1", and the current language to en_EN. if should search for the translations in DOC_ROOT/i18n/ now, it returns the text between the _(); functions, but I get no translation files in said directory, and I also have no clue how to accomplish this. so what I want to accomplish is this: enable use of function _(), which saves all translations in a folder i18n, and subfolder LOCALE_CODE (ex. DOC_ROOT/i18n/en_EN/messages.po). what am I doing wrong, and how can I fix it? thx to any who can help, and if more info is needed, ask and you shall receive.
  2. Hello all, I have a server setup that contains an web application at location x, and a "subdomain" at location y, with a public_html symlink to location x. Now, I've added a virtual host to the system pointing to the symlink in subdomain y. The config files that the application requires to work (subdomain specific) are contained on the same leven as the symlink, so the application would need to move up 1 directory to access the config data. require(../config/config.php) Now the server says it can't access the file, even though it is there. I've managed to fix the problem for now by using this little piece of code: require_once(str_replace('public_html','config/config.php',$_SERVER['DOCUMENT_ROOT'])); But I would guess that doing require('../config/config.php') would do the same... why not? and if possible how can I fix this, because the subdomain folder contains more then just the config data, (also user files etc...) so it would be best if the symlink would work as expected... thx in advance, and if anything is unclear about my question, do let me know, and I'll try to clearify everything. Vhost file (censored): <VirtualHost *:80> ServerName demo.somedomain.org DocumentRoot /home/demo.somedomain.org/public_html <Directory /home/demo.somedomain.org/public_html/> Options Indexes +FollowSymLinks MultiViews AllowOverride All Order allow,deny allow from all </Directory> ErrorLog /var/log/apache2/app/demo.somedomain.org.error.log # Possible values include: debug, info, notice, warn, error, crit, # alert, emerg. LogLevel warn CustomLog /var/log/apache2/app/demo.somedomain.org.access.log combined </VirtualHost>
  3. Found the problem myself. The autoloader checked if the "IGenerator" class already existed, and if not, reincluded it, but it's an interface, so it got included 2x Thx to anyone who took time to read my question
  4. Hello all, I'm developing my own framework on a windows 7 with xampp istalled, and apc enabled. I made a generator controller that can be accessed through php cli, and I can call a generator. But once I try to call a 2nd one, I get a APC error saying it can not re-initialise a interface: C:\Projects\Framework\fw>php framework build:project Creating folder structure...................DONE Creating default files.........DONE C:\Projects\Framework\fw>php framework build:application frontend [Tue Jul 05 15:33:42 2011] [apc-error] Cannot redeclare class igenerator in C:\Projects\Framework\fw\core\objectCollector.class.php on line 397. C:\Projects\Framework\fw> (it crashes on the autoloader) the 'IGenerator' is the only interface I currently have in the framework, and it's used to manage "builders" so the generator object can work with external or custom builders. How can I fix this? or is this a apc core error? IGenerator Code: (but don't think this has anything to do with it) <?php /** * Any class that implements this interface can be registered to the generator as a builder. * @author Darghon */ interface IGenerator { /** * Public construct method receiving a single parameter, * which represents all possible parameters join in an array */ public function __construct($args = array()); /** * Public destroy method that will be triggered when the class gets unset, or destroyed */ public function __destroy(); /** * The method that the generator class will apply. This method must ALWAYS exist, and return a Boolean on success or fail. * @return boolean */ public function generate(); } ?>
  5. I've been playing around with memcached, installed a localhost memcache server, and implemented my registry to save all objects in memcache. Now I don't notice any load increases, at all. which is pretty disappointing, so I was wondering if maybe I was doing it wrong... a test page that loads 24 objects and 7 finders loads in 0.3seconds with the registry (2 objects arrays), and in 0.3seconds with the memcache server (average over 1000 loads) My "MemoryHandler" class handles 2 cases, first case if when you use memcache, 2nd is when you can't. The class is a singleton, so only 1 instance of it will be available at any time. This class is build and maintained by a static call, so you will never declare it yourself Functions that my objects use are the following: ObjectCollector::Memory()->retrieve($class,(option)$id); ObjectCollector::Memory()->register($object); There are 2 types of objects that can be "cached" this way, a businesslayer object (containing data), and a finder (containing database connection data, and sql statements) The following is the code for the memory handler, and if anyone sees anything strange, or wrong, do tell... cause this way, it isn't decreasing my load time... <?php class MemoryHandler{ /** * Mode that specifies that memcached server should be used (if possible) */ const MODE_MEMCACHE = 1; /** * Mode that specifies that the systeem needs to keep a collection during load */ const MODE_REGISTRY = 0; protected $timeout = 30; protected $objectcollection = null; protected $findercollection = null; protected $memcache = null; protected $mode = self::MODE_MEMCACHE; protected $connected = false; public function __construct(){} /** * Public function that registers the added connection data to the memcache object */ public function connect($host, $port = 11211){ return $this->addServer($server,$port); } public function addServers(array $server_array){ foreach($server_array as $server){ if(is_array($server)){ $this->addServer($server["host"],$server["port"]); } else{ $this->addServer($server); } } } public function addServer($host, $port = 11211){ if($this->mode != self::MODE_MEMCACHE) return false; if($this->memcache->addServer($host,$port) === true){ $this->connected = true; return true; } else{ return false; } } public function & register($object){ if($this->mode == self::MODE_MEMCACHE) return $this->register_memory($object); if($this->mode == self::MODE_REGISTRY) return $this->register_registry($object); } private function & register_memory($object){ $class = get_class($object); $id = is_subclass_of($object,'Finder') ? null : $object->getID(); $this->memcache->set($this->generateKey($class,$id),$object,0,$this->timeout); $obj = $this->memcache->get($this->generateKey($class,$id)); return $obj; } private function & register_registry($object){ if(is_subclass_of($object,'Finder') === true){ if(!array_key_exists($object->tag(),$this->findercollection)){ $this->findercollection[$object->tag()] = $object; } return $this->findercollection[$object->tag()]; } else{ if(array_key_exists($object->tag(),$this->objectcollection)){ if(!array_key_exists($object->getID(),$this->objectcollection[$object->tag()])){ $this->objectcollection[$object->tag()][$object->getID()] = $object; } } else{ //If no previous object of this type is stored, the collection is created, and the object is added $this->objectcollection[$object->tag()] = array( $object->getID() => $object ); } return $this->objectcollection[$object->tag()][$object->getID()]; } } public function & retrieve($class, $id = null){ if($this->mode == self::MODE_MEMCACHE) return $this->retrieve_memory($class,$id); if($this->mode == self::MODE_REGISTRY) return $this->retrieve_registry($class,$id); } private function & retrieve_registry($class, $id = null){ if(is_subclass_of($class, 'Finder')){ if(!array_key_exists($class,$this->findercollection)){ $finder = new $class; $this->findercollection[$class] =& $finder; } return $this->findercollection[$class]; } else{ //Set a default variable to be returned if needed (object expected in referenced return) $objdef = false; //If Business object type is already set in the objectCollection Array if(array_key_exists($class,$this->objectcollection)){ //Check if the collection has the object with the requested id if(array_key_exists($id,$this->objectcollection[$class])){ return $this->objectcollection[$class][$id]; } return $objdef; } else{ return $objdef; } } } private function & retrieve_memory($class,$id = null){ if(is_subclass_of($class, 'Finder')){ $obj = $this->memcache->get($this->generateKey($class)); if($obj === false){ return $this->register(new $class); } return $obj; } else{ $obj = $this->memcache->get($this->generateKey($class,$id)); return $obj; } } public function getStats(){ if($this->memcache !== null){ $return = $this->memcache->getStats(); $this->memcache->flush(); return $return; } else{ return 'memcache not loaded'; } } /** * Public function that sets the mode of the memory handler * @param Integer $mode */ public function setMode($mode = self::MODE_MEMCACHE){ $this->mode = $mode; if($this->mode == self::MODE_MEMCACHE){ $this->memcache = new Memcache; } else{ $this->memcache = null; $this->objectcollection = array(); $this->findercollection = array(); } } /** * Public function that retrieves the mode of the memory handler * @return Integer $mode; */ public function getMode(){ return $this->mode; } private function generateKey($class, $id = null){ if($id !== null){ return Tools::encrypt($class.$id); } else{ return Tools::encrypt($class); } } public function __destroy(){ foreach($this as $key => $var){ unset($this->$key); } unset($this); } }
  6. The concept that I had in mind was that I made a block of data, that in case it got full, would kick the least used data. This way the size would remain very limited, (or within control), and everything that needed to be loaded frequently would be "ready-to-use". The system uses nothing but objects, and the global idea is that in case a rather large portion of memory could be used for this, that the system would only get ID's from the database, and if the object ID wasn't found in the cache, that then, and only then the data would come from the database, and otherwise just retrieve it from global repository. not sure if my explenation is clear though...
  7. Hi, I'm creating a webgame in a self made framework. Right now I'm attempting to make each and every request go as fast as possible, and I've been reading up on caching and have made quite a journey to where I am now. Now my next problem is that during the game, some data gets reloaded every single request, and I want to prevent the server for loading the same data 100's of times / minute during peak moments. So I googled some, and found memcached, redis, semaphores, sharedmemory blocks, ... They all look promising, but what should I use... What I want: I want to be able to get a shared object stack in memory, that every process can access. The objects itself will be saved when changed, but the idea is that the server doesn't need to request the data each time someone refreshes a page, but that it can just retrieve it from a shared memory resource. It would even be fantastic if I were able to provide a wrapper that would react on whatever was available, but that's running ahead of myself. Anyone have experience in setting up a shared data resource in php? and if so, how can I do this? Thx for any and all responses
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.