Zend Framework 2 performance optimization: it works

Zend Framework 2 (ZF2) provides optimization techniques that are often overlooked by published performance tests. One excellent source for such techniques is a presentation by Gary Hockin. I was thrilled when my client and friend King Harrison IV of K3S began testing the effect of these techniques on his ZF2 application running on IBM i.

King’s initial tests produced a 600ms reduction in load time, obtaining respectable performance for his database-heavy application. He plans to update his blog post with further speed improvements as he implements them.

Read King Harrison IV’s blog post about ZF2 performance improvements.

Maximize Zend Server PHP performance with Apache compression

Does your site run as quickly as it could? It’s worth your time to find out. Faster web sites sell more products, improve user satisfaction, and even rank higher in Google searches.

Note: This tip was written for IBM i but could be adapted for other platforms as well.

Benefits of Zend Server

If you have upgraded from Zend Core to Zend Server for IBM i, you have already received several performance improvements: bytecode acceleration (Zend Optimizer+), the elimination of Zend Core’s proxy web server, and configurable Data Caching. If you upgraded from Community Edition (CE) to full Zend Server, you also get monitoring, Page Caching, and Job Queue functionality.

Compression adds even more speed

IBM’s Apache web server provides an additional way to speed up your Zend Server for IBM i pages. You can compress PHP output, javascript, style sheets, and other text-based content. The compressed output will automatically be decompressed and interpreted properly by all modern web browsers. My tests show a speed improvement of 10-50% from this easy technique.

How to enable compression in 3 steps

1. Edit ZENDSVR’s Apache configuration file, located at /www/zendsvr/conf/httpd.conf. This is a simple text file, so you may choose from several editors: IBM’s HTTP Server Admin GUI at port 2001 (if *ADMIN is started), the WRKLNK/EDTF command, or your favorite text editor (I use EditPad Pro).

2. Add the following two directives to the httpd.conf’s main section:

# Load IBM i's module that performs compression
LoadModule deflate_module /QSYS.LIB/QHTTPSVR.LIB/QZSRCORE.SRVPGM

# Specify what to compress (example: php, json, css, javascript, static html)
AddOutputFilterByType DEFLATE application/x-httpd-php application/json text/css
application/x-javascript application/javascript text/html

3. Restart Zend Server using the handy Restart PHP button button or STRTCPSVR SERVER(*HTTP) RESTART(*HTTP) HTTPSVR(ZENDSVR)

Measure the improvement

I ran before-and-after tests using a sample script included with Zend Server for IBM i: http://your-server:10088/Samples/SQL_access/DB2_SQL_example.php.

Before compression: 31kb, loaded in 250ms (milliseconds). See the Firebug report below (Firebug is an optional add-on for Firefox and is not required.)

Zend Server output without compression

Without compression, this page was 31kb and loaded in 250ms

After compression: 4.4kb; loaded in 109ms. That’s only 14% of the size and 50% of the time! See the screen shot below.

after compression: only 4.4kb and loaded in 109ms

after compression: only 4.4kb and loaded in 109ms

I highly recommend that you give output compression a try. Your Zend Server for IBM i pages will fly!

For more information on browser output compression, see: http://httpd.apache.org/docs/2.0/mod/mod_deflate.html