> 백엔드 개발 > PHP 튜토리얼 > PHP5.6无法加载curl问题的解决

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

WBOY
풀어 주다: 2016-06-20 12:26:12
원래의
1029명이 탐색했습니다.

curl已加载

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

Call to undefined function curl_init();
로그인 후 복사

环境配置:

  • 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
로그인 후 복사

根据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()函数看不到的现象。


总结:日志很重要!

원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
최신 이슈
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿