Table of Contents
总结:日志很重要!
Home Backend Development PHP Tutorial PHP5.6无法加载curl问题的解决

PHP5.6无法加载curl问题的解决

Jun 20, 2016 pm 12:26 PM

curl已加载

最近在一个项目中需要用到php下的curl扩展,但是在实际运行时遭遇到了curl函数无法执行的问题,页面错误为:

Call to undefined function curl_init();
Copy after login

环境配置:

  • windows 10 64bit
  • Apache 2.4(win32)
  • php 5.6.21 ts

按照常规步骤检查

  1. 用phpinfo()找到php.ini文件路径
  2. extension_dir是否配置正确
  3. extension=php_curl.dll是否打开

结果一切正常,但是phpinfo()的结果里没有curl模块

然后用搜的,网上大多数的解决方案是:

  • 把libeay32.dll,ssleay32.dll放进system32里,重启apache,还有的说要把php5ts.dll也放进去,最接近的是把libssh2.dll放进/bin里
  • 考虑php版本号和php_curl.dll的版本号是否一致
  • 可能要用到libcurl.dll库
  • 检查apache的重启姿势,不能只用httpd -k restart,还要从系统服务里重启

最后朋友给出一种终极方法:把现在的环境干掉,找个集成环境重新装一遍!

这也是个办法,可是我不想重装,咋办?

另外,我还发现了一个奇怪的现象,我在command line下检查加载的模块时,curl是可以加载的,并且可以执行。但是用phpinfo()就是显示没有加载。

接着就再放狗查这个现象,然而没有什么有用的信息。

一个偶然的想法,去看了apache的日志,发现一行:

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
Copy after login

根据apache的错误日志,大概能看出来,这是操作系统没有找到对应的动态链接库。

于是放狗,打开php官方的一篇文档:PHP: 安装 - Manual,查找The operating system cannot run %1.\r\n,找到标题是mtudor AT icefusion remove me DOT co uk ¶的一篇帖子内容,在这篇发布于7年前的帖子里,他讲述了遇到的一个跟这个问题几乎一致的现象!,并对这个问题给出了详细的分析、产生的原因和解决方法。

其中在原因一节,他这样写道:

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.

他主要分析了windows系统查找动态链接库文件的顺序,注意到其中的一段话:

For PHP running under Apache, the application directory is \bin and NOT .

这说明apache可能需要在自己的运行环境里找到libeay32.dll,ssleay32.dll和php_curl.dll这几个文件,但我们并没有把它们从php文件夹下拷到apache/bin下,而是放到了windows/system32中,而并卵。

纠正以后,终于看到了熟悉的结果。而这也正好解释了我能在command line下可以执行curl_init(),但用phpinfo()函数看不到的现象。


总结:日志很重要!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

Explain the concept of late static binding in PHP. Explain the concept of late static binding in PHP. Mar 21, 2025 pm 01:33 PM

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

Framework Security Features: Protecting against vulnerabilities. Framework Security Features: Protecting against vulnerabilities. Mar 28, 2025 pm 05:11 PM

Article discusses essential security features in frameworks to protect against vulnerabilities, including input validation, authentication, and regular updates.

Customizing/Extending Frameworks: How to add custom functionality. Customizing/Extending Frameworks: How to add custom functionality. Mar 28, 2025 pm 05:12 PM

The article discusses adding custom functionality to frameworks, focusing on understanding architecture, identifying extension points, and best practices for integration and debugging.

How to send a POST request containing JSON data using PHP's cURL library? How to send a POST request containing JSON data using PHP's cURL library? Apr 01, 2025 pm 03:12 PM

Sending JSON data using PHP's cURL library In PHP development, it is often necessary to interact with external APIs. One of the common ways is to use cURL library to send POST�...

Describe the SOLID principles and how they apply to PHP development. Describe the SOLID principles and how they apply to PHP development. Apr 03, 2025 am 12:04 AM

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

How does session hijacking work and how can you mitigate it in PHP? How does session hijacking work and how can you mitigate it in PHP? Apr 06, 2025 am 12:02 AM

Session hijacking can be achieved through the following steps: 1. Obtain the session ID, 2. Use the session ID, 3. Keep the session active. The methods to prevent session hijacking in PHP include: 1. Use the session_regenerate_id() function to regenerate the session ID, 2. Store session data through the database, 3. Ensure that all session data is transmitted through HTTPS.

See all articles