Zend framework slow performance

Posted on 2009-03-30
Medium Priority
Last Modified: 2013-11-11
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

Question by:sree01
  • 2
LVL 49

Expert Comment

ID: 24032779
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


Author Comment

ID: 24036921
thanks for your reply.
can you give me an example of the use a custom loader
LVL 49

Accepted Solution

Roonaan earned 500 total points
ID: 24048401
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


Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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.

Join & Write a Comment

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

624 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question