- Dynamic PHP Extensions Not Loading
- Related posts:
- Leave a Reply Cancel reply
- Community
- Resources
- Blog Categories
- Recent Comments
- Partners
- Company
- Php dynamic extension loading
- Description
- Parameters
- Return Values
- Examples
- Notes
- See Also
- User Contributed Notes 4 notes
- Php dynamic extension loading
- Описание
- Список параметров
- Возвращаемые значения
- Примеры
- Список изменений
- Примечания
- Смотрите также
Dynamic PHP Extensions Not Loading
I recently saw an issue on one of our servers where we were trying to enable Zend Optimizer and IonCube Loaders, but they just won’t show up on a phpinfo page despite showing up via command line:
-bash-3.2# php -v
PHP 4.4.9 (cli) (built: May 4 2010 13:55:07)
Copyright (c) 1997-2008 The PHP Group
Zend Engine v1.3.0, Copyright (c) 1998-2004 Zend Technologies
with the ionCube PHP Loader v3.3.14, Copyright (c) 2002-2010, by ionCube Ltd., and
with Zend Optimizer v3.3.3, Copyright (c) 1998-2007, by Zend Technologies
After toggling around with this and finally getting cPanel installed, one of their techs (Kyle P.) figured out that the problem is with PHP being built with the versioning extension, which can apparently cause dynamic modules not to load when PHP is invoked as a DSO (and likely as CGI, but couldn’t reproduce it). The CPanel documentation also recommends against it:
“Versioning – The PHP versioning option was intended to allow the same sort of functionality that the concurrent DSO patches allow. It does not work well and is not recommended by cPanel or the PHP developers.”
Quite honestly, I never used versioning on a server and I knew it wasn’t something that was recommended, but at least now we know why!
Related posts:
Leave a Reply Cancel reply
Community
Resources
Blog Categories
Recent Comments
- Hi There — I do still currently work for IMH, but have moved to RamNode …Vanessa Vasile2023-06-23 21:36:30
- Thank you Vanessa V. Found this after googling the errors I found during the elevation …Casey O’Connor2023-06-20 11:56:49
- halu. you missed ; on the last. should be : find /var/cpanel/ssl/domain_tls/ -mindepth 1 -maxdepth 1 -name .pending_delete …dit2023-02-16 05:30:54
- […] am deploying a new rails 7 app on cpanel whm OS is centos 7, …Deploying rails application on cpanel WHM on centos 7 — TechTalk72022-11-17 11:20:46
- Thank you so much for this! This worked perfectly after weeks of mucking around.Simon2022-11-17 09:19:36
Partners
Company
©2021 TCA Server Solutions, LLC.
Proudly hosted by InMotion Hosting.
This website has no official affiliation with cPanel, LLC.
Php dynamic extension loading
dl — Loads a PHP extension at runtime
Description
Loads the PHP extension given by the parameter extension_filename .
Use extension_loaded() to test whether a given extension is already available or not. This works on both built-in extensions and dynamically loaded ones (either through php.ini or dl() ).
This function is only available for the CLI and embed SAPI s, and the CGI SAPI when run from the command line.
Parameters
This parameter is only the filename of the extension to load which also depends on your platform. For example, the sockets extension (if compiled as a shared module, not the default!) would be called sockets.so on Unix platforms whereas it is called php_sockets.dll on the Windows platform.
The directory where the extension is loaded from depends on your platform:
Windows — If not explicitly set in the php.ini , the extension is loaded from C:\php5\ by default.
- whether PHP has been built with —enable-debug or not
- whether PHP has been built with ZTS (Zend Thread Safety) support or not
- the current internal ZEND_MODULE_API_NO (Zend internal module API number, which is basically the date on which a major module API change happened, e.g. 20010901 )
Return Values
Returns true on success or false on failure. If the functionality of loading modules is not available or has been disabled (by setting enable_dl off in php.ini ) an E_ERROR is emitted and execution is stopped. If dl() fails because the specified library couldn’t be loaded, in addition to false an E_WARNING message is emitted.
Examples
Example #1 dl() examples
// Example loading an extension based on OS
if (! extension_loaded ( ‘sqlite’ )) if ( strtoupper ( substr ( PHP_OS , 0 , 3 )) === ‘WIN’ ) dl ( ‘php_sqlite.dll’ );
> else dl ( ‘sqlite.so’ );
>
>
?php
// Or using PHP_SHLIB_SUFFIX constant
if (! extension_loaded ( ‘sqlite’ )) $prefix = ( PHP_SHLIB_SUFFIX === ‘dll’ ) ? ‘php_’ : » ;
dl ( $prefix . ‘sqlite.’ . PHP_SHLIB_SUFFIX );
>
?>
Notes
Note:
dl() is case sensitive on Unix platforms.
See Also
User Contributed Notes 4 notes
dl is awkward because the filename format is OS-dependent and because it can complain if the extension is already loaded. This wrapper function fixes that:
function load_lib ( $n , $f = null ) return extension_loaded ( $n ) or dl ((( PHP_SHLIB_SUFFIX === ‘dll’ ) ? ‘php_’ : » ) . ( $f ? $f : $n ) . ‘.’ . PHP_SHLIB_SUFFIX );
>
// ensure we have SSL and MySQL support
load_lib ( ‘openssl’ );
load_lib ( ‘mysql’ );
// a rare few extensions have a different filename to their extension name, such as the image (gd) library, so we specify them like this:
load_lib ( ‘gd’ , ‘gd2’ );
function dl_local ( $extensionFile ) //make sure that we are ABLE to load libraries
if( !(bool) ini_get ( «enable_dl» ) || (bool) ini_get ( «safe_mode» ) ) die( «dh_local(): Loading extensions is not permitted.\n» );
>
//check to make sure the file exists
if( ! file_exists ( $extensionFile ) ) die( «dl_local(): File ‘ $extensionFile ‘ does not exist.\n» );
>
//check the file permissions
if( ! is_executable ( $extensionFile ) ) die( «dl_local(): File ‘ $extensionFile ‘ is not executable.\n» );
>
//we figure out the path
$currentDir = getcwd () . «/» ;
$currentExtPath = ini_get ( «extension_dir» );
$subDirs = preg_match_all ( «/\//» , $currentExtPath , $matches );
unset( $matches );
//lets make sure we extracted a valid extension path
if( !(bool) $subDirs ) die( «dl_local(): Could not determine a valid extension path [extension_dir].\n» );
>
$extPathLastChar = strlen ( $currentExtPath ) — 1 ;
if( $extPathLastChar == strrpos ( $currentExtPath , «/» ) ) $subDirs —;
>
//construct the final path to load
$finalExtPath = $backDirStr . $currentDir . $extensionFile ;
//now we execute dl() to actually load the module
if( ! dl ( $finalExtPath ) ) die();
>
//if the module was loaded correctly, we must bow grab the module name
$loadedExtensions = get_loaded_extensions ();
$thisExtName = $loadedExtensions [ sizeof ( $loadedExtensions ) — 1 ];
//lastly, we return the extension name
return $thisExtName ;
Like with eval(), the only correct way to use dl() is to not use it.
Test if a function(s) you intend to use are available.
If not, complain to the user or implement a workaround.
Not to mention dl() issues in a multithreading environment.
If you need to load an extension from the CURRENT local directory because you do not have privelages to place the extension in your servers PHP extensions directory, this function i wrote may be of use to you
/*
Function: dl_local()
Reference: http://us2.php.net/manual/en/function.dl.php
Author: Brendon Crawford
Usage: dl_local( «mylib.so» );
Returns: Extension Name (NOT the extension filename however)
NOTE:
This function can be used when you need to load a PHP extension (module,shared object,etc..),
but you do not have sufficient privelages to place the extension in the proper directory where it can be loaded. This function
will load the extension from the CURRENT WORKING DIRECTORY only.
If you need to see which functions are available within a certain extension,
use «get_extension_funcs()». Documentation for this can be found at
«http://us2.php.net/manual/en/function.get-extension-funcs.php».
*/
function dl_local ( $extensionFile ) <
//make sure that we are ABLE to load libraries
if( !(bool) ini_get ( «enable_dl» ) || (bool) ini_get ( «safe_mode» ) ) <
die( «dh_local(): Loading extensions is not permitted.\n» );
>
//check to make sure the file exists
if( ! file_exists ( $extensionFile ) ) <
die( «dl_local(): File ‘ $extensionFile ‘ does not exist.\n» );
>
//check the file permissions
if( ! is_executable ( $extensionFile ) ) <
die( «dl_local(): File ‘ $extensionFile ‘ is not executable.\n» );
>
//we figure out the path
$currentDir = getcwd () . «/» ;
$currentExtPath = ini_get ( «extension_dir» );
$subDirs = preg_match_all ( «/\//» , $currentExtPath , $matches );
unset( $matches );
//lets make sure we extracted a valid extension path
if( !(bool) $subDirs ) <
die( «dl_local(): Could not determine a valid extension path [extension_dir].\n» );
>
$extPathLastChar = strlen ( $currentExtPath ) — 1 ;
if( $extPathLastChar == strrpos ( $currentExtPath , «/» ) ) <
$subDirs —;
>
//construct the final path to load
$finalExtPath = $backDirStr . $currentDir . $extensionFile ;
//now we execute dl() to actually load the module
if( ! dl ( $finalExtPath ) ) <
die();
>
//if the module was loaded correctly, we must bow grab the module name
$loadedExtensions = get_loaded_extensions ();
$thisExtName = $loadedExtensions [ sizeof ( $loadedExtensions ) — 1 ];
//lastly, we return the extension name
return $thisExtName ;
- PHP Options/Info Functions
- assert_options
- assert
- cli_get_process_title
- cli_set_process_title
- dl
- extension_loaded
- gc_collect_cycles
- gc_disable
- gc_enable
- gc_enabled
- gc_mem_caches
- gc_status
- get_cfg_var
- get_current_user
- get_defined_constants
- get_extension_funcs
- get_include_path
- get_included_files
- get_loaded_extensions
- get_required_files
- get_resources
- getenv
- getlastmod
- getmygid
- getmyinode
- getmypid
- getmyuid
- getopt
- getrusage
- ini_alter
- ini_get_all
- ini_get
- ini_parse_quantity
- ini_restore
- ini_set
- memory_get_peak_usage
- memory_get_usage
- memory_reset_peak_usage
- php_ini_loaded_file
- php_ini_scanned_files
- php_sapi_name
- php_uname
- phpcredits
- phpinfo
- phpversion
- putenv
- set_include_path
- set_time_limit
- sys_get_temp_dir
- version_compare
- zend_thread_id
- zend_version
- get_magic_quotes_gpc
- get_magic_quotes_runtime
- restore_include_path
Php dynamic extension loading
dl — Loads a PHP extension at runtime
Описание
Loads the PHP extension given by the parameter library.
Use extension_loaded() to test whether a given extension is already available or not. This works on both built-in extensions and dynamically loaded ones (either through php.ini or dl() ).
This function has been removed from some SAPI’s in PHP 5.3.
Список параметров
This parameter is only the filename of the extension to load which also depends on your platform. For example, the sockets extension (if compiled as a shared module, not the default!) would be called sockets.so on Unix platforms whereas it is called php_sockets.dll on the Windows platform.
The directory where the extension is loaded from depends on your platform:
Windows — If not explicitly set in the php.ini , the extension is loaded from C:\php4\extensions\ (PHP4) or C:\php5\ (PHP5) by default.
- whether PHP has been built with —enable-debug or not
- whether PHP has been built with (experimental) ZTS (Zend Thread Safety) support or not
- the current internal ZEND_MODULE_API_NO (Zend internal module API number, which is basically the date on which a major module API change happened, e.g. 20010901)
Возвращаемые значения
Возвращает TRUE в случае успешного завершения или FALSE в случае возникновения ошибки. If the functionality of loading modules is not available or has been disabled (either by setting enable_dl off or by enabling безопасный режим in php.ini ) an E_ERROR is emitted and execution is stopped. If dl() fails because the specified library couldn’t be loaded, in addition to FALSE an E_WARNING message is emitted.
Примеры
Пример #1 dl() examples
// Example loading an extension based on OS
if (! extension_loaded ( ‘sqlite’ )) if ( strtoupper ( substr ( PHP_OS , 0 , 3 )) === ‘WIN’ ) dl ( ‘php_sqlite.dll’ );
> else dl ( ‘sqlite.so’ );
>
>?php
// Or, the PHP_SHLIB_SUFFIX constant is available as of PHP 4.3.0
if (! extension_loaded ( ‘sqlite’ )) $prefix = ( PHP_SHLIB_SUFFIX === ‘dll’ ) ? ‘php_’ : » ;
dl ( $prefix . ‘sqlite.’ . PHP_SHLIB_SUFFIX );
>
?>Список изменений
Версия Описание 5.3.0 dl() is now disabled in some SAPI’s due to stability issues. The only SAPI’s that allow dl() are: CLI, CGI and Embed. Use the Extension Loading Directives instead. Примечания
Замечание:
dl() is not supported when PHP is built with ZTS support. Use the Extension Loading Directives instead.
Замечание:
dl() is case sensitive on Unix platforms.
Смотрите также