FutureQuest, Inc. FutureQuest, Inc. FutureQuest, Inc.
Knowledgebase: PHP/MySQL
PHP Includes are slow?
Posted on 28 January 2004 08:17 PM
Question:

It seems as if PHP Includes are taking a long time.

The entire code for this page is:

<?php
include("http://$SERVER_NAME/inc/styles.inc");
echo "$SERVER_NAME: Test Finished.";
?>


and the file to be included is only 3KB (give or take some bytes). Pages with multiple includes have slowed to a crawl.

Can you look into the causes of this and slap whoever is responsible (Unless it's me, then I suggest a stern talking to) ;>.

Answer:

This is in the category of "Don't do that" as it's extremely inefficient... :(

What you are doing is:
browser -> Apache (test.php) <-> Apache (styles.inc)
**extremely inefficient as you are now tying up 2 Apache children to serve a simplistic request

The proper way to do it is via accessing the file directly:
include("/big/dom/xdomain/www/inc/styles.inc");

Going directly to the file is lightning fast in comparison to taxing an Apache child for such a request...

You will want to recode much of your PHP files as I see they are plagued with the 'include URL' method. :(

The true underlying problem to all this is that '*.inc' files are protected by the Apache engine for obvious security reasons. Your 'include' is being denied access by the Apache child, which is causing the delay. Reworking to direct file access solves the problem and removes a ton of overhead.

The following post should explain it:
http://www.FutureQuest.net/forums/showthread.php?s=&threadid=3694

Hope this helps to guide you in the right direction...