5

The web application I am working on needs to be able to handle two different versions of the same PHP extension. (Specifically MapScript for Mapserver 5.6 and MapScript for Mapserver 6.2.)

The script won't know which of the two versions needs to be loaded until after php execution has started. (But only one extension is needed for each request.)

My original plan was to use php built-in dl function, but I discovered that dl has been disabled because of security issues. (http://php.net/manual/en/function.dl.php)

Is there any way secure way to load an extension during execution? Or perhaps always load both, but put them in different namespaces so they can be accessed separately?

Cœur
  • 37,241
  • 25
  • 195
  • 267
alexwells
  • 1,243
  • 13
  • 16
  • unless the extension supports namespaces, you probably can't. There's no mechanism to load plugins/modules and stuff them into a different namespace than the default, e.g. `dl('v1.so', \this\that)`. – Marc B Dec 14 '12 at 15:11
  • If you cannot recompile the two extensions, and if you only need to load both for performing some tests, there is a *header* that identifies uniquely an extension, and you could use a binary editor to change a letter where the extension name appears inside, change also the function names by 1 letter (and also rename the filenames everywhere as well). Disclaimer: didn't try myself. – Déjà vu Feb 14 '13 at 08:39

1 Answers1

2

I've given the question a +1 because it's a good question, well asked.

However, I can't imagine that there will be an answer that will do what you're looking for. If the extension is not backward compatible between versions then it's clearly not well designed, and it's hard to see how PHP can be responsible for that.

The best solution I can think of involves using two separate php.ini or .htaccess files, specifying the two separate versions of the extension. PHP programs run from your web server would pick up different versions of the extension depending on which directory they're in.

eg http://myserver/newmaps/program.php would run the new version of the extension and http://myserver/oldmaps/program.php would run the old version of the extension.

Then you just need to have the same program in two directories. If it detects that it's not got the extension version it needs, it could just issue a http redirect to load the other version.

SDC
  • 14,192
  • 2
  • 35
  • 48
  • Thanks for your response. I was afraid there was no elegant solution when I asked. I'll look into your suggestion, but I suspect it may be more complicated than it is worth. – alexwells Dec 14 '12 at 15:52