#author("2021-10-07T04:40:18+00:00","default:sagasite","sagasite")
[[PHP]] > PHPのsimplexml_load_fileでSSL関連のエラー
RIGHT:2021-10-07 (木) 公開
//RIGHT:2020-05-18 (月) 更新
//----- ----- ----- ----- ----- ----- ----- -----
// 3行以内でこのページの概要を説明
- PHPのsimplexml_load_file()関数でSSL関連のエラーが出たときの対処メモ。
~
//----- ----- ----- ----- ----- ----- ----- -----
//----- KEYWORD BEGIN -----
#html{{
<div class="panel panel-danger">
<div class="panel-heading">キーワード</div>
<div class="panel-body">
}}
//----- KEYWORD BEGIN -----
- simplexml_load_file()
- SSL operation failed with code 1.
//----- KEYWORD END -----
#html{{
</div>
</div>
}}
//----- KEYWORD END -----
//----- CSS for TABLE -----
#html{{
<style type="text/css">
table, td, th { border: 1px #ccc solid; }
td, th { padding: 5px; }
</style>
}}
//----- CSS for TABLE -----
//===== ===== ===== ===== ===== ===== ===== ===== ===== =====
#contents
//===== ===== ===== ===== ===== ===== ===== ===== ===== =====
* PHPのsimplexml_load_file()関数とは? [#l2d37357]
** 公式サイト [#official]
- 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
//===== ===== ===== ===== ===== ===== ===== ===== ===== =====
* エラーメッセージ [#kc0be9bd]
>A PHP Error was encountered
Severity: Warning
>Message: simplexml_load_file(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
//===== ===== ===== ===== ===== ===== ===== ===== ===== =====
* 解決方法 [#o631619b]
- 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。
#code(php){{
$context = stream_context_create(array('ssl'=>array(
'allow_self_signed'=> true,
'verify_peer' => false,
)));
libxml_set_streams_context($context);
$xml = simplexml_load_file($url);
}}
//===== ===== ===== ===== ===== ===== ===== ===== ===== =====
* 参考 [#confer]
- 無効な証明書なサイトに、file_get_contents する方法 - Qiita
https://qiita.com/izanari/items/f4f96e11a2b01af72846
- (現在は解決しました)PHPの外部への接続でSSLのエラーが出てしまう@KUSANAGI PHP7.2 - Qiita
https://qiita.com/yousan/items/dc2cc789dcb0f07a61dc
//----------------------------------------
// A8 Ads - sakura VPS banner
~
#html{{
<center><a href="http://px.a8.net/svt/ejp?a8mat=1O73NW+3B2PRM+D8Y+BXB8X" target="_blank"><img border="0" width="468" height="60" alt="" src="http://www21.a8.net/svt/bgt?aid=101108300200&wid=001&eno=01&mid=s00000001717002003000&mc=1"></a><img border="0" width="1" height="1" src="http://www18.a8.net/0.gif?a8mat=1O73NW+3B2PRM+D8Y+BXB8X" alt=""></center>
}}
//----------------------------------------