Solved

Zend framework slow performance

Posted on 2009-03-30
4
1,298 Views
Last Modified: 2013-11-11
Hi,
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

Sree
0
Comment
Question by:sree01
  • 2
4 Comments
 
LVL 49

Expert Comment

by:Roonaan
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.

1]
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)

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

3]
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.

4]
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.

5]
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.

6]
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

Arnoud
0
 

Author Comment

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

Accepted Solution

by:
Roonaan earned 125 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');
define('DIR_LIB','/absolute/path/to/application/classes/folder');

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

Arnoud
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

0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

746 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now