PHP 5.6 cannot load curl problem solved curl already loaded
Recently, a project needs to use curl extension in php, but the curl function cannot be executed during actual running. the page error is:
Call to undefined function curl_init();
Environment configuration:
- Windows 10 64bit
- Apache 2.4 (win32)
- Php 5.6.21 ts
Check by regular steps
- Use phpinfo () to find the php. ini file path
- Is extension_dir correctly configured?
- Extension = php_curl.dll enabled
The result is normal, but no curl module is found in the result of phpinfo ().
Most of the solutions on the Internet are:
- Put libeay32.dll and ssleay32.dll in system32, restart apache, and put php5ts. dll in another way. put libssh2.dll in/bin.
- Check whether the php version and php_curl.dll version are consistent.
- Libcurl. dll library may be used
- Check the apache restart posture. you cannot only use httpd-k restart, but also restart from the system service.
Finally, a friend provides the ultimate method:Kill the current environment and find an integrated environment to reinstall it!
This is also a solution, but I don't want to reinstall it. what should I do?
In addition, I also found a strange phenomenon. when I checked the loaded modules under command line, curl can be loaded and executed. However, if phpinfo () is used, it indicates that the file is not loaded.
Then let the dog look up this phenomenon, but there is no useful information.
By chance, I checked apache logs and found a line:
PHP Warning: PHP Startup: Unable to load dynamic library 'C:\\Server\\php\\ext\\php_curl.dll' - The operating system cannot run %1.\r\n in Unknown on line 0
According to the apache error log, we can see that the dynamic link library is not found in the operating system.
Put The dog on, open a php official document: PHP: Install-Manual, find The operating system cannot run % 1. \ r \ n, locate a post titled mtudor AT icefusion remove me DOT co uk branch. in this post published seven years ago, he told me aboutThe problem is almost the same!And provides detailed analysis, causes, and solutions for this problem.
In the reason section, he wrote:
CAUSE ----- This was caused by PHP picking up the wrong versions of libeay. dll and ssleay. dll, which were present in multiple locations on my computer.
When any application attempts to use a dll file in windows, the system searches for this file using the following order:
- The directory from which the application loaded.
- The windows \ system32 directory.
- The windows \ system directory.
- The windows directory.
- The current directory.
- The directories that are listed in the PATH environment variable.
Http://msdn.microsoft.com/en-us/library/ms682586.aspx)
For PHP running under Apache, the application directory is \ bin and NOT . PHP was finding out of date versions of libeay. dll and ssleay. dll in \ bin (probably installed when I enabled SSL support in my web server ). because of this, the latest versions in windows \ system32 were never reached.
He mainly analyzed the order of searching for dynamic linked library files in windows, and noticed one of them:
For PHP running under Apache, the application directory is \ bin and NOT .
This indicates that apache may need to find the libeay32.dll, ssleay32.dll, and php_curl.dll files in its own runtime environment, but we didn't copy them from the php folder to apache/bin, instead, it is stored in windows/system32.
After the correction, we finally saw the familiar results. This also explains how I can execute curl_init () in command line, but I cannot see it using the phpinfo () function.
Conclusion: logs are very important!