Solution to the problem of loading curl in PHP5.6-php Tutorial

Source: Internet
Author: User
Tags apache error log
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

  1. Use phpinfo () to find the php. ini file path
  2. Is extension_dir correctly configured?
  3. 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:

  1. The directory from which the application loaded.
  2. The windows \ system32 directory.
  3. The windows \ system directory.
  4. The windows directory.
  5. The current directory.
  6. 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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.