unloading php extensions : reverse dl()
Asked Answered
C

3

4

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

Civics answered 23/5, 2012 at 8:10 Comment(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.Lobate
@Lobate : originated from HttpResponse classname collision between pecl_http and Cakephp 2.1... sigh, looks like I will have to wait till the next release.Civics
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')) { // ... }Lobate
Q
3

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.

Quarterdeck answered 23/5, 2012 at 8:11 Comment(0)
H
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.

Hattiehatton answered 23/5, 2012 at 8:27 Comment(0)
A
-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.

Apothem answered 29/2, 2016 at 11:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.