PHP 5.3+ enable_dl not enabling dl()?
Asked Answered
T

1

7

I am trying to install a 3rd party PHP extension (.so) into PHP 5.3.6-13 on Ubuntu 11.10 and use it in a web environment. The vendor's documentation suggests using the dl() function to dynamically load the library.

When I try their example code, I find the dl() isn't available (Fatal error: call to undefined function dl()) as dl() function was deprecated in PHP 5.3. But there is an enable_dl config rule in php.ini, and other sources say that I should be able to use dl() simply by changing the php.ini variables (enable_dl=On, safe_mode=Off, not listed in disable_functions) and restarting apache. When I try that, dl() is still undefined.

So I dig into the PHP 5.3 SAPI change notes and find this:

The dl() function is now disabled by default, and is now available only under the CLI, CGI, and embed SAPIs.

Does this mean that dl() is not only "disabled by default" in PHP 5.3+ using a web SAPI, but actually "completely unavailable no matter what I do even with modifying PHP config options"? That's what it appears to me to be since I can't get dl() to work no matter what I tweak.

To clarify: I can modify php.ini and load the extension directly, so this is not a question about how to get the extension working, rather about the function dl() and its state in PHP 5.3+. If it's no longer available under any circumstance I want to be able to tell the vendor, so they can update their documentation. But if it should be available and I'm just missing something, I'd like to hear that too.

Thyroiditis answered 31/8, 2012 at 19:46 Comment(6)
Which SAPI are you using for PHP? Apache Module?Part
apache2handler. I mentioned restarting apache in there but I guess I never did explicitly state that I was using apache.Thyroiditis
oh and apache 2.2.20 if that helpsThyroiditis
Dynamic loading is not available for apache2handler any longer. That's why you can not get it to work. More important than the server (and it's version) is actually the type of SAPI module, here you are using the apache module for PHP. That means, PHP is executed inside apache and not in it's own process like with (F)CGI or in CLI. dl() has been disabled for security reasons. You do not want to have new stuff loaded in the process context of your webserver ;) - Or better :( in your case, because you will not get it to work. Howver as you can edit the ini file, you can just load the extensionPart
Great - how do you know this? is there documentation anywhere? if you make an answer with a reference to somewhere it says that apache2handler doesn't support dynamic loading, I'll mark it right :)Thyroiditis
The manual has the info ;) I added it as an answer I hope this is more clear for you now.Part
P
3

This function has been removed from some SAPIs in PHP 5.3. -- dl()

So if you have the ini setting enable_dl set to on and it still does not work, then it is disabled in the SAPI you use.

If you wonder which SAPIs are meant, the changelog on that same page is more detailed:

The only SAPIs that allow dl() are CLI and Embed.

You are not using any of these two. Instead use the Extension Loading Directives and you're fine.

Part answered 1/9, 2012 at 10:12 Comment(6)
Oh I thought you had some knowledge specific to the apache2handler. That's good enough - although there again you used the term 'disabled' in regards the SAPI - the whole point of the question is that it's not merely disabled but completely unavailable.Thyroiditis
If it is disabled on the PHP engine level, it feels for you like being completely unavailable. In fact, the feature is still in your php binary, but really disabled (on the engine level), it's not meant that there is an ini-setting you can re-enable it. So merely a wording issue, sometimes it is not easy to describe technical cicumstances clear for everybody, that's why we ask ;)Part
@hakre, What kind of SAPI is "Embed"?Tabescent
@Pacerier: For embedding PHP, for example as a scripting engine in your own binaries I think.Part
@hakre, No it's very likely the docs are talking about a specific SAPI called "Embed".Tabescent
@Pacerier: Which could be needed if you want to embed PHP as a scripting engine?Part

© 2022 - 2024 — McMap. All rights reserved.