php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #48839 dl is incorrect disabled instead of deprecated
Submitted: 2009-07-07 18:49 UTC Modified: 2010-01-13 01:48 UTC
From: pkwan at advsofteng dot net Assigned: kalle (profile)
Status: Closed Package: Documentation problem
PHP Version: 5.3.0 OS: *
Private report: No CVE-ID: None
 [2009-07-07 18:49 UTC] pkwan at advsofteng dot net
Description:
------------
According to the PHP documentation, the "dl" function is deprecated, but not disabled. So it should continue to work. The followings are the supporting documentation as published in http://www.php.net/dl


- 5.3.0 This function now throws an E_DEPRECATED notice on all sapi's except for CLI, CGI and Embed.  

- As of PHP 5, the dl() function is deprecated in every SAPI except CLI. Use Extension Loading Directives method instead. 

- Since PHP 6 this function is disabled in all SAPIs, except CLI, CGI and embed. 


The above means "dl" is disabled in some SAPI only starting from PHP 6. Even in PHP 6, "dl" should continue to work in CLI, CGI and embed.

In PHP 5, "dl" is deprecated but not disabled. It should work in CLI, CGI, Embed, and at most throws a E_DEPRECATED notice in other SAPI.


In practice, "dl" does not work in CGI, and no E_DEPRECATED notice is throw in any case. After some trouble-shooting, the code that causes the problem is (located in cgi_main.c):

if (!cgi && !fastcgi && !bindpath) {
   cgi_sapi_module.additional_functions = additional_functions;
}

The above disables the "dl" function in CGI usage, conflicting with the documentation.




Reproduce code:
---------------
<?php dl("any_name.dll"); ?>


Expected result:
----------------
If the above code is executed in CGI, no error message is expected. 



Actual result:
--------------
Fatal error: Call to undefined function dl() in
C:\Inetpub\Scripts\phpinfo.php on line 1


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-07-08 00:05 UTC] pajoye@php.net
I'm not sure what you are using but dl works with cgi:

C:....\php530>php-cgi.exe t.php
X-Powered-By: PHP/5.3.0
Content-type: text/html

<br />
<b>Warning</b>:  dl() [<a href='function.dl'>function.dl</a>]: Unable to load dynamic library 'C:\php5\any_name.dll' - T
he specified module could not be found.
 in <b>C:\....\t.php</b> on line <b>1</b><br />

 [2009-07-08 06:36 UTC] pkwan at advsofteng dot net
But you are using php-cgi in the command line, not as a CGI.

If you actually used php-cgi as a CGI, the code in "cgi_main.c" will detect that it is used as a CGI (by checking the CGI environmental variables), and disables "dl". This is done by the following code in "cgi_main.c".

if (!cgi && !fastcgi && !bindpath) {
   cgi_sapi_module.additional_functions = additional_functions;
}
 [2009-07-08 09:21 UTC] pajoye@php.net
moved this bug as a doc bug. 
 [2009-07-08 10:37 UTC] pkwan at advsofteng dot net
Are you sure you want it do be a doc bug?

CGI PHP will be very inefficient and has very poor performance without "dl".

It is because in CGI, PHP needs to be restarted for every PHP request. Without "dl", all extensions have to be defined in "php.ini". It means PHP needs to load all extensions for every PHP request, even if the extensions are not used by a script.

I would think it is reasonable to load extensions using "php.ini" for the PHP Apache module, because PHP is only started once as an Apache module. However, for CGI PHP, it is a poor design to load extensions using "php.ini". Using "dl" is much more reasonable.

In my opinion, the original documentation to allow "dl" to be used for "CLI" and "CGI" seems to be a good design.
 [2009-07-08 10:40 UTC] pajoye@php.net
Yes, I'm sure. There are reasons why it has been done (avoid crashes being one of them). Also I don't see how performance can be affected by the dl removal (using dl is slow) :)
 [2009-07-08 11:20 UTC] pkwan at advsofteng dot net
Your point about the performance of "dl" is valid for PHP as an Apache module. However, for CGI, the reverse is true. "dl" is much more efficent than "php.ini".

If you have tested it in a real and typical CGI environment, you can see that CGI PHP becomes very slow without "dl".

In a typical PHP environment, there may be around 10 to 20 extensions. Without "dl", the extensions must be listed in "php.ini". It means the CGI PHP must load all these 20 extensions running each PHP script (remember, in CGI, the PHP is restarted for each request), even if a typical PHP script only used none or a few extensions. This is the cause of the slowness.

I know "dl" is slower than "php.ini" if PHP is an Apache module, but it is much faster than the "php.ini" for if it is a CGI.

For the "avoidance of crash", may be you are correct, as I did not have enough experience in "avoidance of crash". However, I suspect much of the crashing problems is when PHP is when it is used as an Apache module. It should be much more stable in CGI. 

It is because CGI is never multi-threaded, and it is always used by one script only. Remember in CGI, each script is handled by a separate PHP process, which is only used once for that instance of the script. It is hard to see why "dl" can be more crash prone than using "php.ini" in CGI. 

Finally, even if the PHP dies, it affects only that instance of the script. For CGI, the PHP process will terminate anyone at the end of the script. So it should not affect the stability of the system.
 [2009-07-08 15:03 UTC] pkwan at advsofteng dot net
I would like to add that this problem is not win32 only, but affects all OS. (I changed the OS field to "All OS".) As CGI is important for non-Windows OS, so I think this issue is important.
 [2010-01-13 01:48 UTC] svn@php.net
Automatic comment from SVN on behalf of kalle
Revision: http://svn.php.net/viewvc/?view=revision&revision=293476
Log: Fixed bug #48839 (dl is incorrect disabled instead of deprecated)
 [2010-01-13 01:48 UTC] kalle@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.


 [2020-02-07 06:09 UTC] phpdocbot@php.net
Automatic comment on behalf of kalle
Revision: http://git.php.net/?p=doc/en.git;a=commit;h=a8a3ab994fced8dc6c943fc622cc6058e81596c2
Log: Fixed bug #48839 (dl is incorrect disabled instead of deprecated)
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sun Jul 13 18:01:32 2025 UTC