PHP 忽略 php.ini 中的 curl.cainfo 设置(显然)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23392159/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
PHP ignoring curl.cainfo setting in php.ini (apparently)
提问by mercurial
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".
我正在尝试修复 Windows 服务器(运行 IIS)上的 php_curl 调用,该调用返回熟悉的错误“SSL 证书问题,验证 CA 证书是否正常。详细信息:错误:14090086:SSL 例程:SSL3_GET_SERVER_CERTIFICATE:证书验证失败”。
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:
正如这里的许多相关问题中所详述的,我下载了http://curl.haxx.se/ca/cacert.pem,将其移动到我服务器的硬盘驱动器,并将 curl.cainfo 设置添加到我的 php.ini 中:
curl.cainfo = "C:\path\to\cacert.pem"
Nothing, still getting the same error. However, specifying the path in the PHP code results in a successful response!
没什么,仍然得到同样的错误。但是,在 PHP 代码中指定路径会导致成功响应!
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CAINFO, "C:\path\to\cacert.pem");
$response = curl_exec($ch);
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.
这确实给了我一个我现在可以使用的解决方法,但我在很多地方维护一个带有 php_curl 调用的大型应用程序,所以在 php.ini 中指定一次这个设置会更合乎逻辑,所以它适用于所有 php_curl 调用应用程序。
Potential dumb mistake checking:
潜在的愚蠢错误检查:
- I'm restarting IIS between php.ini edits
- I know I'm editing the right php.ini, because "echo ini_get('smtp_port');" reflects changes I make to that setting (changing a non-critical setting just for testing)
- I know IIS can read the file, because it works when setting it using curl_setopt() (above)
- 我在 php.ini 编辑之间重新启动 IIS
- 我知道我正在编辑正确的 php.ini,因为“echo ini_get('smtp_port');” 反映我对该设置所做的更改(更改非关键设置仅用于测试)
- 我知道 IIS 可以读取该文件,因为它在使用 curl_setopt() 设置它时可以工作(上图)
Trying to look at the ini setting directly shows that PHP doesn't seem to know anything about it (am I doing this right?):
试图直接查看 ini 设置表明 PHP 似乎对此一无所知(我这样做对吗?):
var_dump(ini_get('curl.cainfo'));
==> bool(false)
Any ideas why PHP wouldn't read the curl.cainfo setting?
为什么 PHP 不会读取 curl.cainfo 设置的任何想法?
回答by mercurial
Holy macaroni, a coworker just solved this mystery for me. Leaving it here in case it helps someone else.
神圣的通心粉,一位同事刚刚为我解开了这个谜团。把它留在这里以防它帮助别人。
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
这个 curl php.ini 设置直到 PHP 5.3.7 才被添加:http: //www.php.net/manual/en/curl.configuration.php#ini.curl.cainfo
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 没有从 php.ini 读取该设置。就那么简单。