Skip Navigation LinksHome > Categories > Code from a Category

Accelerating the ZF-projects: avtoload and assembly in one file.

User Name: serfcompany
Name: Serf
Contact Me:
Home Page:
php,mysql,javascript,html,css. Preferable working with Zend Framework. Good know javascript. I worked with various, javascript frameworks such as(jquery, YUI3, extjs, sencha touch). [More]
Viewed Times: 1822
Add Date: 06/21/2012
Subject of the article is to increase productivity Zend Framework applications by assembling and startup framework into a single file

Description of the idea

As you can see Zend Framework consists of a set of files that are placed in convenient folders.
The structure meets the full class name, which is very convenient - you do not have long to find and understand.
That was one side of the coin.
The second issue is the huge number of files, which connects with every request, creating quite a heavy load on your server

Naturally such an application may not be fast, when each request for 300-400 jerks files.
The application would work much faster if the files were in a less ... either to all the classes were all in a single file, right?

The solution I've only seen in two ways:

1.Building the Library into a single file.
2. Build a library of PHP extensions.

The second option, I represent a technically bad, because the with the server software mark the surface. As far as I know, you can somehow put the byte-code libraries as an extension, but how? I myself can not imagine this.
This can be done either C-programmer, or a good administrator of the server software. But, unfortunately, that's not me.

So, I was only one option: to collect all in one PHP file. But I will not, I collect everything framework files into one file, why should I do?
After some thought, I came to the conclusion that you can build a file with only the necessary classes through the startup, if you write your avtoloader.

In avtoloader enter only those classes that are used. We check whether this is not loaded class in memory, if so, avtoloader does nothing.
If not - connect the class, write the class in the compiled file. In the subsequent application starts missing a class will already be entered in the assembly file and will not connect more.

Which method will give a huge performance boost. The larger the files used in the project and the more files will be written in the assembly file - the higher the performance of the system, compared to what it was before the introduction of this mechanism.


As always, the most delicious part. For a start will give you the code created by the autoloader. Some parts of the code have been taken here, but I have been sharpened by the task. I am in the above example does not like the implementation. Once it was all too confusing. I did this for simplicity to two classes, a modular file and 2 lines in the bootstrap. First, even tried to write everything completely myself, until I realized that I was not very good at regular expressions and do not see the above article.

Actually the code is very simple and well documented, so the details of his work I see no reason to present. Here's another: class Exception:

These two classes and working on our task. Now let's configure our bootstrap file. Add these lines of code after the initialization include_path

All integration into your project is completed. But, as revealed not so smooth as we would like. Assembled file will still have to correct your hands, because There are all sorts of problems. But I do not think it is very difficult - in fact it should be done only once.

Of course, for that all have successfully worked to cut out all require_once.

Now your assembly file will grow. Avtoload will be included, but when they collected all the classes, it just will not be called.


Following the successful integration and assembly into a single file you should notice a significant performance boost. At the same time is highly recommended to use the byte-code Kesher for maximum effect.
Talk about some specific numbers are very difficult: it all depends on the specifics of your system.
Fast you project!

Post a Comment

Name: (Optional)
Email: (Optional, you can get an email if somebody replys your comments)*
Email me if somebody respons my comment below:
Enter Text
as Below:
(case insensitive, if hard to read, click the "get a new one" button)
* Your email address will not be shared with any third parties for any reason.
** Maximum 1000 charactors.