tags:

views:

31

answers:

1

I have a modified version of PHP which is compiled to PHP, in PHP. I'm not interested in a discussion about why I shouldn't be doing this; best practice, standards, etc; so please don't.

It's not modified in the core, but crudely uses a PHP script to modify each PHP file before being evaluated. Because of the performance hit of modfiying each file, I am currently caching each file, however this is not an ideal solution because:

  • Two copies of each file are stored
  • It's possible to modify the wrong file
  • Servers with crappy hosting don't allow file_put_contents(), so the cache has to be updated on the local server

An alternative solution is to evaluate each file at runtime, however this incurs an overhead and also requires eval(), which may be slower and doesn't give the same error messages as include().

I'd like to know if there's a better way to do this, preferably one that works on servers that don't allow file_put_contents().

+1  A: 

Does your server have access to any shared memory caches? APC, memcache, etc? APC sounds like a decent fit for this.

sunetos
Something like APC would be very useful if I could modify each PHP file before it is cached with APC. Do you know if this is possible?
peterjwest
Since you're on a shared hosting environment, I doubt you could use any global hooks to catch the file before going to bytecode. However, you could just use APC at a high level to cache the modified string source of your files and then do the eval() approach that you mentioned. The benefit with APC is that you could easily cache both a before and after version of each file's contents.
sunetos
Just to clarify, I mean storing the source with apc_store/apc_fetch.
sunetos
That sounds perfect, but why would I need to cache the 'before version' of each file?
peterjwest
Oh, I have no idea, because I don't entirely understand your project. It just seemed like the type of thing that might be useful.
sunetos