Zend framework slow performance

I just started using zend framework for a project.But it is very slow in performance.I am using the Zend_Loader::registerAutoload method.Is there any way to improve performance.My Ajax request takes more than 10 seconds to get reponse.

thanks in advance

Who is Participating?
RoonaanConnect With a Mentor Commented:
Sure, no problem, sorry for the long wait,

The code expected two defines to be made:

define('DIR_ZF', '/absolute/path/to/zendframework/library');

Note that you can just define the __autoload function, and php will pick it up.

An additional note to this is that the 'else' clause is doing an include once rather than doing an is_file. Depending on your application, you need to decide if you want to include an is_file clause, or just want to use it this way.

Kind regards

function __autoload($class_name) {
  if(strpos($class_name,'Zend') === 0) {
    require_once DIR_ZF . DIRECTORY_SEPARATOR .  str_replace('_', DIRECTORY_SEPARATOR , $class_name . '.php');
  } else if(strpos($class_name, 'My_Application') === 0) {
    require_once DIR_LIB . DIRECTORY_SEPARATOR .  str_replace('_', DIRECTORY_SEPARATOR , $class_name . '.php');
  } else {
    include_once str_replace('_', DIRECTORY_SEPARATOR , $class_name . '.php');

Open in new window

10 seconds is indeed very slow. ZF however is known to be slower than other frameworks, but this is too slow.

There are a multitude of areas you can tweak ZF on, I used I think at least 8 methods involving different approaches on a recent application.

I know that the default Zend_Session is locking its session file during the whole request, instead of closing it when done writing.

Certainly for AJAX based environments where multiple request happen at the same time asynchroneously, this leads to the behavior that still the requests are processed one after another.

Before diving deeper, are you using multiple asynchroneous requests at the same time? (You can use firebug or a IE equivalent to see which HTTP requests are made and their wait/response times)

Implementing caching on your configuration files. This saves a lot of parsing

Instead of using Zend autoload, use a custom loader that does no file_exists check on Zend_* classes, but just includes them. I can show you code later, but have to get some sleep first.

When using any form of autoloading, Make a copy of your ZF install (ZF_Opt for instance) and remove all require_once statements. Include all files using absolute paths instead of relative ones. This saves path resolving by lower level processes.

You can use a controller plugin to track the includes being made within certain modules. Then on consecuetive requests include the files in preDispatch using absolute paths. This causes less lookup.

You can merge different related Zend_* files into single package files.
For example:
1) Copy Zend_Controller.php Zend_Controller_Front.php and other Zend_Controller to a ZendController.package.php.
2) Write an include_once 'ZendController.package.php'; in each original file
This will cause all classes to become available when a single one of them is called

7] Implement full page caching

8] Use more local variable to store $config->something->something->something references. Because in ZF classes with overloaded properties, an array_key_exists is used for each time you access a property, causing you to do unnecessairy processing.

9] Use APD or XDebug to find more bottleneck.

This is just a start of things I could think of for now. I'll get some sleep and we can dive deeper tomorrow.

Kind regards

sree01Author Commented:
thanks for your reply.
can you give me an example of the use a custom loader
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.