0

I have a similar problem as here

I am using Apache2 server.

I have made a simple extension named extensionV2.so I can load the extension and use it in my code when i do

extension = extensionV2.so in php.ini.

and use its functions in my php file.

But if i use

<?php

dl('extensionV2.so');
var_dump(get_loaded_modules());

?>

I get the error

Fatal error: Call to undefined function dl() in /var/www/html/My.php on line 9

Note:

I am using php 5.3

According to phpinfo()

Thread Safety - disabled
Safe Mode - Off
enable_dl()  = On

I get the desired output via php -r in the terminal. I am aware of dl() not in use anymore via apache2handlers... is there any alternate option to workaround the dl() issue?

Community
  • 1
  • 1
Suvarna Pattayil
  • 5,136
  • 5
  • 32
  • 59

1 Answers1

1

You don't need to dl() for loading your extension, if your extension is compatible with your PHP (PHP-extension should match the PHP server in thread safety, API number and compiler version) then, after restarting your server you should see your extension name (in your case extensionV2) in your phpinfo() page, otherwise there is a problem in loading your extension.
EDIT-1

Here is an alternate for using dl() in your code:

// Try to load our extension if it's not already loaded.
if (!extension_loaded('extensionV2')) {
  if (strtolower(substr(PHP_OS, 0, 3)) === 'win') {
    if (!dl('extensionV2.dll')) return;
  } else {
    // PHP_SHLIB_SUFFIX gives 'dylib' on MacOS X but modules are 'so'.
    if (PHP_SHLIB_SUFFIX === 'dylib') {
      if (!dl('extensionV2.so')) return;
    } else {
      if (!dl('extensionV2.'.PHP_SHLIB_SUFFIX)) return;
    }
  }
}
A23149577
  • 2,045
  • 2
  • 40
  • 74
  • Thanks @Amir.Sorry for replying late! By saying "You don't need to dl() for loading your extension",did you mean either editing the php.ini file to contain extension = extensionV2.so or use dl() in my code to load at runtime? Simply,placing the .so file in the `/usr/lib/php/modules` directory and restarting the server, Executing `php -r 'echo testExtFn();'` gives `Fatal error:Call to undefined function testExtFn() in Command line code on line 1` After adding `extension = extensionV2.so to php.ini`, the problem got resolved. Did you specify some other approach which i didnt comprehend? – Suvarna Pattayil Mar 19 '13 at 15:44
  • Obviously, I did not understand your question, I edited my answer, hope it helps. – A23149577 Apr 06 '13 at 09:43