5

To you gurus out there, is there any hidden gem in PHP that could unload a specific extension at runtime ?

3
  • What possible reason would you have for this? Just because an extension is loaded, doesn't mean you have to use it. If for some reason you absolutely need to remove a function, you could do it with runkit although I suspect if (!function_exists()) { // ... } or simply disabling it in php.ini with disable_functions would be more appropriate. Commented May 23, 2012 at 8:16
  • @DaveRandom : originated from HttpResponse classname collision between pecl_http and Cakephp 2.1... sigh, looks like I will have to wait till the next release. Commented May 23, 2012 at 8:35
  • Ugly work around would be to modify the CakePHP source and either rename/remove the class definition or wrap in in if (!class_exists('HTTPResponse')) { // ... } Commented May 23, 2012 at 9:33

3 Answers 3

4

No, that's not possible and most likely never will:

[2011-02-08 11:34 UTC] [email protected]
extension unloading on a per-request basis simply isn't feasible from a performance point of view. And you obviously can't unload and leave it unloaded for the next request because that next request may be for a page that expects the extension to be there.

However, using dl() is discouraged anyway - and in recent versions it is only available in the CLI version.

Sign up to request clarification or add additional context in comments.

Comments

1

From another perspective: It's not possible to remove an extension from a running PHP interpreter, as it may have modified the state of the PHP interpreter in an irreversible fashion. For instance, many extensions register classes when loaded; there's no code in these modules to deregister these classes when unloaded. Worse yet, if your script is already running, it may already contain instances of these classes, which would crash the interpreter if manipulated with the class definition gone.

Comments

-1

As for workaround, if you are using PHP CLI or its built-in server (php -S), you can always specify -n/--no-php-ini to ignore your php.ini, so it'll unload all your extension at runtime. Useful for testing.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.