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

7e9b51c9cdd1

curl已加载

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

Call to undefined function curl_init();

环境配置:

windows 10 64bit

Apache 2.4(win32)

php 5.6.21 ts

按照常规步骤检查

用phpinfo()找到php.ini文件路径

extension_dir是否配置正确

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:

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.

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

总结:日志很重要!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值