Search code examples
phpphp-extension

How to load two versions of the same php extension?


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?


Solution

  • 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.