views:

276

answers:

2

I have a PHP site where all pages include an 57K generated PHP file. I'm thinking of using an opcode cache, so the file doesn't need to be parsed for every time a page is loaded (I assume loading the already parsed file would be faster than reading the 57K source file).

APC seems to be good candidate for this, but according to phpinfo my Godaddy shared hosting doesn't have it compiled in and I can't compile and install it in a shared hosting enviroment. The Zend framework is installed, but according to the docs it also needs APC or an other opcode cache as a backend.

What other options do I have to perform opcode caching? Is there a PHP-only opcode caching solution which I could simply FTP to godaddy?

A: 

Is there a PHP-only opcode caching solution which I could simply FTP to godaddy?

Unfortunately, no. By the time a .php file runs, it's already too late as the interpret and compile actions have already been performed.

Therefore, it must run as a PHP extension, which are compiled...

R. Bemrose
Okay, but if that PHP file loads an other PHP file (the above mentioned generated file) then I could imagine a PHP package which would provide a load_opcode_if_possible("x.php") function and this function would try to load an already prepared opcode file first and if it's not available then it would read the source code file and write immediately a parsed opcode file to the disk which would be used next time.
Tom
@Tom: In theory you could do this, but it'd have its own penalty, as PHP (as far as I know) pulls in included/required files during the interpret phase before compilation.
R. Bemrose
A: 

Reading a file PHP file, parsing it, compiling it to opcodes, and executing the opcodes, is all done internally by the internal PHP engine -- which means a PHP script has absolutly no control over this process ; and which also means the only way to alter that process is via a PHP extension (PHP extension means an extension developped in C), which have a much higher level of control.

This means there is no way to get an opcode-cache developped in pure-PHP : opcode manipulations, compilation, and caching are operations you cannot control from PHP.

And as PHP extensions have access to the internals of the engine, only administrators of the server can install and enable them -- considering they can crash PHP, eat up any amount of memory they want, you can probably understand why.

So, unfortunatly, there is not much hope for you : if you want to use an opcode cache like APC, you'll have to go with some hosting service that provides it -- which might mean using your own dedicated server.

Pascal MARTIN