Jack, 
could you please paste the formatted code on the http://paste2.org/ or
elsewhere. It would be easier to look at.

Summarizing...
To get better performance (at the time) of ZF you need to remove all
require_once from lib classes and write your own autoloader based on SPL?
Right?
(of course using caching to gain performance is obvious)

Although in 
http://www.nabble.com/Zend_Form-and-generating-fields-td18826312.html#a18830980
one thread  Matthew said that performance audit is considered for 1.7
release I hope the changes which speed up autoloading will appear asap.
Sooner than 2.0 ;)



Jack Sleight wrote:
> 
> Here is the script I've written to remove the require_once and loadClass 
> calls from ZF. This does not fix the HelperBroker issue, that change 
> will need applying manually.
> -- 
> Jack
> 
> <?php
> class OptimiserFilterIterator extends FilterIterator   
> {  
>       public function accept()  
>       {  
>               return (pathinfo($this->current(), PATHINFO_EXTENSION) === 
> 'php');  
>       } 
> }
> 
> $directory = 'zend-framework/library/';
> 
> $iterator = new RecursiveDirectoryIterator($directory);  
> $iterator = new RecursiveIteratorIterator($iterator,
> RecursiveIteratorIterator::LEAVES_ONLY);  
> $iterator = new OptimiserFilterIterator($iterator);  
> 
> /* Global Replacements */
> 
> foreach($iterator as $i => $file) { 
>       $path = $file->getRealPath();
>       $content = file_get_contents($path);
>       
>       // Remove all Zend library require|include(_once) statements
>       $content =
> preg_replace('/((?:require|include)(_once)?\s?\(?[\'"]Zend\/.*?[\'"]\)?;)/',
> '//$1', $content);
>       
>       // Replace all calls to Zend_Loader::loadClass() with 
> spl_autoload_call()
>       // This will break any calls that use the 2nd $paths parameter, there 
> are
> currently (1.5.3) none
>       $content = preg_replace('/Zend_Loader::loadClass\((.*?)\);/',
> 'spl_autoload_call($1);', $content);
>                       
>       file_put_contents($path, $content);
> }
> 
> /* Specific Changes */
> 
> // Zend/Cache.php
> $content = file_get_contents($directory . 'Zend/Cache.php');
> $content = str_replace(
>       'require_once str_replace(\'_\', DIRECTORY_SEPARATOR, $frontendClass) .
> \'.php\';',
>       'spl_autoload_call($frontendClass);',
>       $content
> );
> $content = str_replace(
>       'require_once str_replace(\'_\', DIRECTORY_SEPARATOR, $backendClass) .
> \'.php\';',
>       'spl_autoload_call($backendClass);',
>       $content
> );
> file_put_contents($directory . 'Zend/Cache.php', $content);
> 
> // Zend/Memory.php
> $content = file_get_contents($directory . 'Zend/Memory.php');
> $content = str_replace(
>       'require_once str_replace(\'_\', DIRECTORY_SEPARATOR, $backendClass) .
> \'.php\';',
>       'spl_autoload_call($backendClass);',
>       $content
> );
> file_put_contents($directory . 'Zend/Memory.php', $content);
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Overriding-Zend_Loader%3A%3AloadClass%28%29-tp18905575p18938254.html
Sent from the Zend Framework mailing list archive at Nabble.com.

Reply via email to