PHP忽略curl.cainfo设置在php.ini(显然) [英] PHP ignoring curl.cainfo setting in php.ini (apparently)
问题描述
我正在尝试修复在Windows服务器(运行IIS)上返回的常见错误SSL证书问题,验证CA证书是否正确的php_curl调用详细信息:
错误:14090086:SSL例程:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed。
I'm trying to fix a php_curl call on a Windows server (running IIS) that is returning the familiar error "SSL certificate problem, verify that the CA cert is OK. Details: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed".
如许多相关问题所述,我下载了 http://curl.haxx.se/ca/cacert.pem ,将其移动到我的服务器的硬盘驱动器,并将curl.cainfo设置添加到我的PHP。 ini:
As detailed in many related questions here, I downloaded http://curl.haxx.se/ca/cacert.pem, moved it to my server's hard drive, and added the curl.cainfo setting to my php.ini:
curl.cainfo = "C:\path\to\cacert.pem"
没有,仍然得到相同的错误。但是,指定PHP代码中的路径会得到成功的响应!
Nothing, still getting the same error. However, specifying the path in the PHP code results in a successful response!
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CAINFO, "C:\path\to\cacert.pem");
$response = curl_exec($ch);
这给了我一个解决方法我现在可以使用,但我维护一个大型应用程序php_curl调用在许多地方,所以在php.ini中指定这个设置更合乎逻辑,所以它适用于应用程序中的所有php_curl调用。
This does give me a workaround I can use for now, but I'm maintaining a large application with php_curl calls in many places, so it would be more logical to specify this setting once in php.ini so it applies to all php_curl calls in the application.
潜在的愚蠢的错误检查:
Potential dumb mistake checking:
- 我在php.ini编辑之间重新启动IIS
- 编辑正确的php.ini,因为echo ini_get('smtp_port');
- 我知道IIS可以读取该文件,因为它在使用curl_setopt()()设置时可以正常工作,
尝试查看ini设置直接表明PHP似乎不知道任何关于它(我这样做吗? ):
Trying to look at the ini setting directly shows that PHP doesn't seem to know anything about it (am I doing this right?):
var_dump(ini_get('curl.cainfo'));
==> bool(false)
任何想法为什么PHP不会读取curl.cainfo设置?
Any ideas why PHP wouldn't read the curl.cainfo setting?
推荐答案
圣经通心粉,一个同事刚刚为我解开了这个谜。
Holy macaroni, a coworker just solved this mystery for me. Leaving it here in case it helps someone else.
此curl php.ini设置在PHP 5.3.7之前未添加: http://www.php.net/manual/en/curl.configuration.php#ini.curl.cainfo
This curl php.ini setting was not added until PHP 5.3.7: http://www.php.net/manual/en/curl.configuration.php#ini.curl.cainfo
我使用的特定测试服务器运行的版本比这个版本旧,因此PHP不会从php.ini读取该设置。很简单。
The particular test server I was working with was running an older version than that, so PHP wasn't reading that setting from php.ini. Simple as that.
这篇关于PHP忽略curl.cainfo设置在php.ini(显然)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!