Page 1 of 1

Very slow remotely included PHP files

Posted: Fri Oct 27, 2006 3:24 pm
by auriga
Hi there!

I have a VPS containing some domains of mine. Each domain will only be able to see it's own dedicated space (folders) on the server. Also, each will get some data from a central database using a php file that contains the queries. This database is located on a dedicated domain, and cannot be directly polled by any of the other domains. This because the database is too large to be copied to every domain.

To get text from the database (poll the database), i use a script located on that central domain (with the database). This PHP script is called as follows:

print include($PATH_TO_CENTRAL_FILE.'?param=$param');

$param will give the necessary information to the database (will be put in the query) to get the data from it. The data that the file gets from the database will be send back to the resp. webpage and printed there.

When i ran the webpage on the domain, i noticed that it's very slow. Now I ran the linux command ab (Apache Benchmarking) on this webpage. Here are the results for different scenarios:

Without database polling, without the include (the file at $PATH_TO_CENTRAL_FILE is not used at all in the webpage):

137.36 #/sec

The file will only return text, no database polling (no queries run on the database):

0.73 #/sec

The file will poll the database, but not return any results (the webpage gets an empty string):

0.96 #/sec

The file will poll the database and send the results to the webpage (normal scenario):

0.79 #/sec

It appears that whenever I send data back from an included PHP file, the webpage gets incredibly slow. Notice that the webpage still is very slow if i do not poll the database (no query is executed)! (?!)

Note: using require_once instead of include doesn't change the speed...

Therefore, I think it has something to do with the way that inclusions of different (absolute) paths are handled by PHP versus calling a procedure inline your html code. If you include a file using

print include(http://www.mydomain.com/.../afile.php?params=$params);

seems to be a lot slower than

include(afile.php);
and then call
print myFunctionInFile($params);

with afile.php in the same folder as the webpage.

Do I make any sense at all? And if so, does anybody know a way to speed things up?

Thanks in advance!

Posted: Fri Oct 27, 2006 3:35 pm
by feyd
Remote inclusion will always be slower than a direct reference and should be avoided at all costs. You don't need to send the included script any parameters if done locally, all variables that your current script has access to, it will as well.

Posted: Fri Oct 27, 2006 5:27 pm
by RobertGonzalez
What type of database is it? It just seems that it would be easier to set each domain up as a user that has access to only those tables that it should, then hit the database directly instead of including a file that does it.