gog's info

<?php echo array_rand(array('web', 'dev', 'computers')); ?>

Removing require_once() calls from Zend Framework

with one comment

If you are using Zend_Loader to load your classes in Zend Framework, there is no need for all the require_once() calls that are littered all over ZF files.

Some acctually report big improvements in responsiveness of their applications and increase in number of transactions per second their hardware can handle because require_once() is quite an expensive operation, especially if the required file is already included prior to the call.

If you are wondering how to comment out all the require_once() calls from your Zend Framework without doing it by hand here is the solution. Navigate to the folder where your installation of ZF resides on the server and just enter this into your shell:

find ./ -type f -exec sed -i 's/require_once/\/\/require_once/' {} \;

My box is running PHP 5.2.6 with APC 3.0.19 and Zend Framework 1.7 PR and my include path is optimized for use with ZF. Stripping require_once() calls didn’t make a drastic impact on my setup and average performance gain was around 3 requests per second (from 63 to 66).

Update (May 16, 2009.)

Since the release of Zend Framework 1.8 there is a script to strip requre_once calls from ZF in the ZF Performance guide. This script does not remove require_once calls to the new Zend_Loader_Autoloader component.

% cd path/to/ZendFramework/library
% find . -name '*.php' -not -wholename '*/Loader/Autoloader.php' -print0 | \
xargs -0 sed --regexp-extended --in-place 's/(require_once)/\/\/ \1/g'

Written by Goran Jurić

October 16th, 2008 at 12:39 am

One Response to 'Removing require_once() calls from Zend Framework'

Subscribe to comments with RSS or TrackBack to 'Removing require_once() calls from Zend Framework'.

  1. Hi,
    The snippet just above didn’t work for me:
    -problem with -wholename predicat

    So I used your previous one that fixed it like a charm.

    Thx

    Raymond

    7 Jul 10 at 22:28

Leave a Reply