我是 php 新手,在尝试加载证书时遇到此错误
jameys-macbookpro41:~ user$ php -f ~/Sites/providerService.php
警告:stream_socket_client():无法设置本地证书链文件“cert.pem”;在第 27 行的/Users/jamey/Sites/providerService.php 中检查您的 cafile/capath 设置是否包含您的证书及其颁发者的详细信息
cert.pem 与 php 文件位于同一文件夹中。文件 cert.pem 是在 Apple 钥匙串(keychain)工具中创建的
class pushNotifications {
...
private $sslPem = 'cert.pem';
...
function connectToAPNS(){
$streamContext = stream_context_create();
stream_context_set_option($streamContext, 'ssl',
'local_cert', $this->sslPem);
感谢您的帮助!
最佳答案
您遇到错误是因为它试图在您运行脚本的目录中找到您的 cert.pem 文件,而不是脚本所在的目录。在您的示例中,它是您的用户目录“~”。
尝试将您的类(class)更改为此或类似内容:
class pushNotifications {
...
private $sslPem = 'cert.pem';
...
function connectToAPNS(){
$streamContext = stream_context_create();
stream_context_set_option($streamContext, 'ssl', 'local_cert', dirname(__FILE__) . '/' . $this->sslPem);
关于php - 在 PHP 中使用 ssl 证书时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/809682/