Zend Framework Classloading Performance
Posted: August 25th, 2009 | Author: Jan Gorman | Filed under: Code, Hint | Tags: Amazon, Autoloading, bash, classloading, Cloud, deployment, gsed, mac, micro-optimization, os x, performance, phing, PHP, require_once, S3, sed, Zend Framework | No Comments »As outlined in the Zend Framework Documentation it’s possible to speed things up a little by removing (almost) all require_once calls from the Framework and relying solely on the autoloading mechanism. I haven’t benchmarked this and I’m fairly certain that it’s a case of micro-optimization but I thought I’d give it a try anyway. The snipped posted there has some minor problems on OS X however. For one the -wholename parameter for find isn’t implemented (can be replaced with -path) and although sed does work, you need to use gsed if you want to pass the arguments as described in the documentation. So here’s the OS X version of the snippet:
find . -name '*.php' -not -path '*/Loader/Autoloader.php' \ -not -path '*/Application.php' -print0 | \ xargs -0 gsed --regexp-extended --in-place 's/(require_once)/\/\/ \1/g'
Update: As part of my new job we’re currently working on a merchandise management system which is hosted somewhere in the Amazon S3 Cloud. The performance impact of removing all the require_once calls was very dramatic on that system. So looks like this hint can come in handy after all in certain situations. What I now did is add the snippet to the phing deployment task that takes care of updating Zend Framework. Since it’s hardly any effort at all there really isn’t any reason not to do this.