PHP > PHPのsimplexml_load_fileでSSL関連のエラー
2021-10-07 (木) 公開
- PHPのsimplexml_load_file()関数でSSL関連のエラーが出たときの対処メモ。
キーワード
- simplexml_load_file()
- SSL operation failed with code 1.
PHPのsimplexml_load_file()関数とは? †
公式サイト †
- PHP: simplexml_load_file - Manual
https://www.php.net/manual/ja/function.simplexml-load-file.php
- PHP: 定義済み定数 - Manual(simplexml_load_fileの設定オプション値)
https://www.php.net/manual/ja/libxml.constants.php
エラーメッセージ †
A PHP Error was encountered
Severity: WarningMessage: simplexml_load_file(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
解決方法 †
- SSL operation failed simplexml_load_file - Google 検索
https://www.google.com/search?q=SSL+operation+failed+simplexml_load_file
- hanhan's blog - simplexml_load_file で自己署名証明書を許容する方法
https://blog.hanhans.net/2018/06/16/simplexml-load-file/
simplexml_load_fileを呼び出す前に下記のコードにて、stream_contextを設定してあげればいい。
なお、 'allow_self_signed'=> trueまたは'verify_peer' => falseのいずれかを設定すればOK。
1 2 3 4 5 |
|
参考 †
- 無効な証明書なサイトに、file_get_contents する方法 - Qiita
https://qiita.com/izanari/items/f4f96e11a2b01af72846
- (現在は解決しました)PHPの外部への接続でSSLのエラーが出てしまう@KUSANAGI PHP7.2 - Qiita
https://qiita.com/yousan/items/dc2cc789dcb0f07a61dc