20
19

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

[PHP] HTTP_Request2のSSLエラーの対処方法

Last updated at Posted at 2014-06-17

HTTP_Request2でhttp通信はできたけど、
接続先をhttpsにしただけでエラーが出た場合の対処方法のメモ。

Unable to connect to ssl://example.com:443. Error: stream_socket_client(): unable to connect to ssl://example.com:443 (Unknown error)
stream_socket_client(): Failed to enable crypto
stream_socket_client(): SSL operation failed with code 1. OpenSSL Error messages:
error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed 

方法1. ssl_capathを指定する

デフォルトのSocketアダプターを使う場合は、SSL証明書のディレクトリ・パスを指定する。

$request = new HTTP_Request2('https://example.com');
$request->setConfig(array(
	'ssl_capath' => '/etc/ssl/certs', // ubuntuの場合
));

方法2. cURLアダプターを使う

cURLアダプターを使えば何もしなくていい。

$request = new HTTP_Request2('https://example.com');
$request->setAdapter('curl');

PHPのcURLエクステンションが入ってない場合は以下のコマンドでインストール。

sudo apt-get install php5-curl

参考

20
19
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
20
19

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?