PhpRiot
News Archive
PhpRiot Newsletter
Your Email Address:

More information

PHP Includes file generator

Note: This article was originally published at Planet PHP on 20 April 2280.
Planet PHP

While profiling SabreDAV, I noticed a few times more than half of the request time was spent in the autoloader.

So instead of autoloading, now I prefer to unconditionally include every file for each package (there are 5 packages). For a while I manually maintained these files manually, but a while back I automated this process.

This is how you run it:

  1. phpincludes . includes.php

This will generate a file such as:

  1. A
  2. // Begin includes
  3. include __DIR__ . '/Interface1.php';
  4. include __DIR__ . '/Class1.php';
  5. include __DIR__ . '/Class2.php';
  6. include __DIR__ . '/Class3.php';
  7. // End includes

You can edit everything before "// Begin includes" and after "// End includes". Subsequent edits will only replace the lines in between those comments.

The script will automatically expand classes and interface dependencies and load them in the correct order. It also has support for a PHP 5.2-compatible syntax (dirname(__FILE__) instead of __DIR__).

If you like it, head over to github, or install it with:

  1. pear channel-discover pear.sabredav.org
  2. pear install sabredav/PHPIncludes