Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 2.2.0

Request #15337 Speeding up the schema loading
Submitted: 2008-12-17 22:13 UTC
From: hovenko Assigned: beni
Status: Closed Package: Net_LDAP2 (version 2.0.0RC4)
PHP Version: 5.2.3 OS: Linux
Roadmaps: 2.0.0    
Subscription  
Comments Add Comment Add patch


Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know! Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem : 13 + 41 = ?

 
 [2008-12-17 22:13 UTC] hovenko (Knut-Olav Hoven)
Description: ------------ One new instance variable and one new method for Net/LDAP2.php to support Net_LDAP2->schema in caching of the LDAP schema. Before I wrote this it took around 1.5 seconds to lookup the LDAP schema, now it takes next to nothing. Hope this helps. Test script: --------------- private $_schema_cache = null; /** * Register a callback function to be able to cache the LDAP schema. * This might make your code go around 1-2 seconds faster. * Please, notice that you need to flush the cache if you make changes to * the schema. * * Example code: * <code> * // note: you should really make your own, don't use /tmp/php.cache * public function schema_cacher($schema = NULL) { * if ($schema === NULL) { * if (file_exists("/tmp/php.cache") * && $schema = unserialize( * file_get_contents("/tmp/php.cache") * )) { * return $schema; * } * } * else { * file_put_contents( * "/tmp/php.cache", * serialize($schema) * ); * } * * return false; * } * $ldap->register_schema_cache('schema_cacher'); * </code> * */ public function register_schema_cache($callback) { if (!is_callable($callback)) { return new PEAR_Error("Schema cache is not callable"); } $this->_schema_cache = $callback; } // schema method with needed changes /** * Get a schema object * * @param string $dn (optional) Subschema entry dn * * @access public * @return Net_LDAP2_Schema|Net_LDAP2_Error Net_LDAP2_Schema or Net_LDAP2_Error object */ public function &schema($dn = null) { // NEW CODE if ($this->_schema_cache) { $schema = call_user_func($this->_schema_cache); if ($schema) { $this->_schema = $schema; } } // Fetch schema, if not tried before. // If we are already fetching the schema, we will skip fetching. if ($this->_schema === null) { if (!$this->_schema instanceof Net_LDAP2_Schema) { // store a temporary error message so subsequent calls to schema() can // detect, that we are fetching the schema already. // Otherwise we will get a infinite loop at Net_LDAP2_Schema::fetch() $this->_schema = new PEAR_Error('Schema not initialized'); $this->_schema = Net_LDAP2_Schema::fetch($this, $dn); // NEW CODE if ($this->_schema_cache) { call_user_func($this->_schema_cache, $this->_schema); } } } return $this->_schema; } Expected result: ---------------- faster code?

Comments

 [2008-12-20 09:31 UTC] doconnor (Daniel O'Connor)
Hey Knut, do you know how to create a patch? Basically: * CVS checkout * Make your changes there * Test them * cvs diff -u > patch.diff.txt * Upload that to the bug
 [2008-12-21 22:36 UTC] hovenko (Knut-Olav Hoven)
The hardest part is to figure out the path to the CVS repo...
 [2008-12-22 08:28 UTC] beni (Benedikt Hallinger)
Checking out a private readonly copy is described at: http://php.net/anoncvs.php The following command should export you a copy of current CVS trunk: `cvs -d :pserver:cvsread@cvs.php.net:/repository checkout pear/Net_LDAP` That idea is not bad, i think i will implement that together with some config option, so users are able to turn that on by request. The Schema handling is (should be) done through the schema class, so there is the right place to put some cache-flushing option in; because of the config option it should not be hard to detect if caching is on or not. Thanks for this improvement idea!
 [2009-01-07 17:53 UTC] beni (Benedikt Hallinger)
Hello again, Daniel! A patch would be mostly welcome, since it would make implementation easier for me. See my previos post, where i describe how to do that. If you have any questions, please let me know.
 [2009-04-30 16:59 UTC] beni (Benedikt Hallinger)
-Status: Analyzed +Status: Closed
This has been implemented now in CVS. However, i found it better to implement that as a interface, e.g. users need to write their own class implementing the new Net_LDAP2_SchemaCache interface. A default implementation is available in form of the class Net_LDAP2_SimpleFileSchemaCache, that servers a file based schema cache with a maximum age. Thanks for your request!