Reputation: 1104
I have once PHP file that I include to pretty much everything I call. This one include file has several other php files that it includes. The reason I use this one file for all my including is because I have path differences between my dev and production server and it is nice to only have to include one file and know that I have the classes that I need right there.
Is there any easy way to cache the file, or something to speed up my load times?
Upvotes: 2
Views: 1454
Reputation: 146450
There are many ways to handle path differences than do not involve loading everything every time. You can, for instance, define a constant and use it as prefix in all your file system operations:
define('DOC_ROOT', '/var/www/foo');
require_once DOC_ROOT . '/lib/bar.php';
Or you can rely in your system's DOCUMENT_ROOT variable (if set and correct):
require_once $_SERVER['DOCUMENT_ROOT'] . '/lib/bar.php';
Or you can use class autoloading. Or you can use include_path.
Apart from that, PHP will always find and parse every file with PHP source code you instruct it to, every time you run your script. You can shorten the second part if you install an opcode cache.
Upvotes: 2
Reputation: 13405
You can install an opcode cache for PHP
An opcode cache optimizes performance by removing the compilation time of PHP scripts by caching the compiled state of PHP scripts into RAM and uses the compiled version straight from the RAM. This will increase the rate of page generation time. It also means your files will only be included once.
Upvotes: 3