本文介绍了在 PHP 中使用 ssl 证书时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 php 新手,在尝试加载证书时遇到此错误

I am new to php and I am getting this error trying to load a cert

jameys-macbookpro41:~ user$ php -f ~/Sites/providerService.php

警告:stream_socket_client():无法设置本地证书链文件cert.pem";检查您的 cafile/capath 设置是否在第 27 行的/Users/jamey/Sites/providerService.php 中包含您的证书及其颁发者的详细信息

Warning: stream_socket_client(): Unable to set local cert chain file `cert.pem'; Check that your cafile/capath settings include details of your certificate and its issuer in /Users/jamey/Sites/providerService.php on line 27

cert.pem 与 php 文件位于同一文件夹中.文件 cert.pem 是在 Apple 钥匙串工具中创建的

cert.pem is in the same folder as the php file. the file cert.pem was created in the Apple keychain tool

class pushNotifications {
...
     private $sslPem = 'cert.pem';
...
     function connectToAPNS(){
          $streamContext = stream_context_create();
          stream_context_set_option($streamContext, 'ssl',
             'local_cert', $this->sslPem);

感谢您的帮助!

推荐答案

您收到一个错误,因为它试图在您运行脚本的目录中找到您的 cert.pem 文件,而不是脚本所在的目录.在您的示例中,它是您的用户目录~".

You are getting an error because it's trying to find your cert.pem file in the directory you are running the script from, not the directory the script is in. In your example, it is your user directory "~".

尝试将您的课程更改为此或类似的内容:

Try changing your class to this, or something similar:

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 中使用 ssl 证书时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-07 00:25