|
|
 |
dl (PHP 3, PHP 4, PHP 5) dl -- Carga una extensión PHP en tiempo de
ejecución Descripciónint dl ( string biblioteca )
Carga la extensión PHP dada por el
parámetro biblioteca. El
parámetro biblioteca
es únicamente el nombre de archivo de
la extensión a cargar, el cual también depende de
su plataforma. Por ejemplo, la extensión sockets (si fue compilada como
módulo, ¡que no es el comportamiento
predeterminado!) podrÃa
llamarse sockets.so en plataformas Unix,
mientras que se llama php_sockets.dll en la
plataforma windows.
Devuelve TRUE si todo se
llevó a cabo correctamente, FALSE en caso
de fallo. Si la funcionalidad de carga de módulos
no está disponible (ver Nota) o ha sido deshabilitada (ya
sea mediante la desactivación de
enable_dl o activando safe mode en php.ini)
un E_ERROR es producido y se detiene la
ejecución. Si dl() falla porque la
biblioteca especificada no pudo ser cargada, se emite un mensaje
E_WARNING en compañÃa del
FALSE.
Use extension_loaded() para probar si una
cierta extensión ya se encuentra disponible o no. Esto
funciona tanto con extensiones integradas como con las cargadas
dinámicamente (ya sea mediante php.ini
o dl()).
La función dl() es obsoleta a partir de
PHP 5. Use el método de las Directivas de Carga de Extensiones
en su lugar.
Ejemplo 1. Ejemplos de dl() |
<?php
if (!extension_loaded('sqlite')) {
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
dl('php_sqlite.dll');
} else {
dl('sqlite.so');
}
}
if (!extension_loaded('sqlite')) {
$prefijo = (PHP_SHLIB_SUFFIX === 'dll') ? 'php_' : '';
dl($prefijo . 'sqlite.' . PHP_SHLIB_SUFFIX);
}
?>
|
|
El directorio desde donde es cargada la extensión depende
de su plataforma:
Windows - Si no está definida explÃcitamente en
php.ini, la extensión es cargada
desde c:\php4\extensions\ por defecto.
Unix - Si no está definida explÃcitamente en
php.ini, el directorio de extensiones predeterminado depende de
si PHP ha sido compilado con --enable-debug o
no
si PHP ha sido compilado con soporte ZTS (Zend Thread Safety)
(experimental) o no
el valor interno ZEND_MODULE_API_NO actual
(número interno de API de módulo Zend, el cual
es básicamente la fecha en la que ocurrié un
cambio significativo en la API de módulo,
p.ej. 20010901)
Tomando en cuenta lo anterior, el directorio recibe el valor
predeterminado
de <dir-instalacion>/lib/php/extensions/
<debug-o-no>-<zts-o-no>-ZEND_MODULE_API_NO,
p.ej.
/usr/local/php/lib/php/extensions/debug-non-zts-20010901
o /usr/local/php/lib/php/extensions/no-debug-zts-20010901.
Nota:
La
función dl() no
es soportada en servidores Web multi-hilos. Use la
sentencia extensions en su php.ini cuando
trabaje sobre ese tipo de entornos. Sin embargo, ¡las
versiones CGI
y CLI no
son afectadas!
Nota:
dl() es sensible a mayúsculas y
minúsculas en plataformas Unix.
Vea también Directivas de
Carga de Extensión
y extension_loaded().
docey
30-Dec-2005 09:37
just some note to loading modules, they do not have to
be executable.
some examples below check for this but if an module is
not executable is does not mean you cant use it. it just
needs to be readable NOT executable.
although some modules might need this perhaps for some
reason i cannot think of, so here an example,
// fails to load mysql although it could be loaded.
if(is_executable("mysql.so")){
dl("mysql.so");
}
// loads mysql
if(is_readable("mysql.so")){
dl("mysql.so");
}
watch out with this, as you can see mysql.so would not be
loaded and the script would fail. because its checked for
executable permissions although these are not needed.
mag_2000 at front dot ru
06-Dec-2005 11:13
<?php
function dl_local( $extensionFile ) {
if( !(bool)ini_get( "enable_dl" ) || (bool)ini_get( "safe_mode" ) ) {
die( "dh_local(): Loading extensions is not permitted.\n" );
}
if( !file_exists( $extensionFile ) ) {
die( "dl_local(): File '$extensionFile' does not exist.\n" );
}
if( !is_executable( $extensionFile ) ) {
die( "dl_local(): File '$extensionFile' is not executable.\n" );
}
$currentDir = getcwd() . "/";
$currentExtPath = ini_get( "extension_dir" );
$subDirs = preg_match_all( "/\//" , $currentExtPath , $matches );
unset( $matches );
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--;
}
$backDirStr = "";
for( $i = 1; $i <= $subDirs; $i++ ) {
$backDirStr .= "..";
if( $i != $subDirs ) {
$backDirStr .= "/";
}
}
$finalExtPath = $backDirStr . $currentDir . $extensionFile;
if( !dl( $finalExtPath ) ) {
die();
}
$loadedExtensions = get_loaded_extensions();
$thisExtName = $loadedExtensions[ sizeof( $loadedExtensions ) - 1 ];
return $thisExtName;
}?>
james at gogo dot co dot nz
18-Jul-2005 04:30
WARNING: enable_dl/dl()
*********************
There is an exploit circulating currently which takes advantage of dl() to inject code into Apache which causes all requests to all virtual hosts to be redirected to a page of the attackers choice.
All operators of shared web hosting servers with Apache and PHP should disable dl() by setting enable_dl to off otherwise your servers are vulnerable to this exploit.
This exploit is generally known as flame.so (the object that is loaded into Apache) and flame.php (the php script that loads it).
Google gives more information:
http://www.google.co.nz/search?q=flame.so+flame.php
nutbar at innocent dot com
18-Mar-2004 01:22
For those who are tearing their hair out due to the extension_dir being set to "./", here's a somewhat graceful fix that will be portable:
dl(preg_replace('/\/([^\/]+)/', '../', dirname(__FILE__)) . __FILE__ . '/../some/path/dll.so');
You could alternatively make that preg_replace part into a separate function and call it something like dirname_rel() or whatever. It basically replaces all the path components with ".." and spits out a relative path, so that when mixed with the "./" part of the extension_dir setting, it puts you at the root folder "/" so that you know where you are :)
endofyourself at yahoo dot com
18-Oct-2003 04:12
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/http://indices.com.es/function.dl.html
Author: Brendon Crawford <endofyourself |AT| yahoo>
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/http://indices.com.es/function.get-extension-funcs.html".
*/
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--;
}
$backDirStr = "";
for( $i = 1; $i <= $subDirs; $i++ ) {
$backDirStr .= "..";
if( $i != $subDirs ) {
$backDirStr .= "/";
}
}
//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;
}//end dl_local()
-------------------------
tychay at php dot net
05-Jul-2003 08:15
Alan isn't 100% correct (though he's close). The exception is Mac OS X. This operating system makes a distinction between dynamically loadable shared libraries and and loadable modules of code (bundles). The former has an extension .dylib and the latter has an extension .so. The former is in Mac-O and the latter is in ELF.
Thus PHP's extensions are built as .so whereas the symbol PHP_SHLIB_SUFFIX is bound (currently) to .dylib. I don't think this is the correct behavior, but nonetheless, it is the behavior as of PHP-5.0.0b2-dev. Right now, the config binds to SHLIB_SUFFIX_NAME (which is correctly bound to .dylib on Mac OS X). I imagine this is related to why there is so much trouble getting dl() to work on Mac OS X. (For instance, I have no trouble phpizing in a new shared library, but when compiling in stuff as shared... much evilness!)
BTW, to get dl() to work in Mac OS X you need to install the dlcompat library (via Fink, DarwinPorts, or Gentoo ports). Remember in the case of Fink, you better make sure your environment variables are adjusted to point to where dlcompat (and your other fink libraries) are.
terry
| |
| | Citas célebres | La primera tarea del poeta es desanclar en nosotros una materia que quiere soñar. Gaston Bachelard Filósofo y ensayista francés (1884-1962) | | Citas en tu mail | | ©Contenidos Gratis |
| Chiste de... Médicos | | Tres pechos | - Doctor, doctor, que veníamos porque mi mujer tiene tres pechos.
- ¡Ah! Y quiere que le extirpe uno de ellos, ¿verdad?
- No, que me implante a mí otra mano | | Chistes en tu mail | | ©ContenidosGratis |
| Inicio | Acción | Estrategia | Palabras | Puzzles | Solitarios | Foro Trucos |  | Cake Mania Jugadores: 6835 Categoría del juego: Acción Objetivo del juego: Ayuda a Jill a recuperar la pastelería de su abuela llevando su propia pastelería; consigue clientes y gana dinero. |
|  | Rainbow Web Jugadores: 2199 Categoría del juego: Puzzles Objetivo del juego: Rompe un pegajoso hechizo y salva un reino de fantasía en Rainbow Web. Tendrás toneladas de diversión mientras juegas a este mágico desafío para la mente. |
|  | Mahjongg Fortuna Jugadores: 12462 Categoría del juego: Solitarios Objetivo del juego: Velocidad y habilidad mental son las armas más importantes en esta versión de un antiguo juego asiático. Despeja el tablero lo antes posible haciendo clic en las fichas iguales y gánate la fama eterna de la puntuación más alta. |
|  | Chainz 2 Jugadores: 6955 Categoría del juego: Puzzles Objetivo del juego: Entra en el mundo de las combinaciones con Chainz 2: Relinked, emocionante secuela del exitazo del año pasado, Chainz. Gira eslabones y crea combinaciones de 3 ó más. |
|  | Delicious Jugadores: 4405 Categoría del juego: Acción Objetivo del juego: ¿Eres un as de la multitarea? ¿Quieres que tus clientes estén contentos? ¡Pues Delicious es tu juego! Sacia el apetito de los clientes y tenlos contentos; ¡no te arriesgues! |
|  | Bookworm Jugadores: 4568 Categoría del juego: Palabras Objetivo del juego: Junta las letras para formar palabras. ¡Las palabras más largas valen más puntos! |
|  | Zuma Jugadores: 4976 Categoría del juego: Acción Objetivo del juego: Controla el ídolo de la rana de piedra de los antiguos Zuma en este intrigante enigma de acción. ¡Dispara bolas para formar conjuntos de tres, pero si dejas que lleguen a la calavera dorada morirás! |
|  | Jewel of Atlantis Jugadores: 3798 Categoría del juego: Puzzles Objetivo del juego: Descubre la ciudad hundida de la Atlántida y busca valiosos tesoros. Viaja más allá de las profundidades del mar y vive trepidantes aventuras en Jewel of Atlantis. |
|  | Jewel Quest Jugadores: 3727 Categoría del juego: Puzzles Objetivo del juego: Convierte la arena de la antigua selva en oro tan rápido como puedas juntando grupos de 3 elementos. ¡Los grupos más grandes valen más puntos! |
|  | Bejeweled 2 Jugadores: 3659 Categoría del juego: Puzzles Objetivo del juego: Con cuatro modos de juego únicos y fascinantes, nuevas piezas de juego explosivas e imponentes fondos planetarios, Bejeweled 2 es mucho más adictivo que nunca. |
|
|