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()関数とは?

公式サイト

エラーメッセージ

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

解決方法

simplexml_load_fileを呼び出す前に下記のコードにて、stream_contextを設定してあげればいい。
なお、 'allow_self_signed'=> trueまたは'verify_peer' => falseのいずれかを設定すればOK。

  1
  2
  3
  4
  5
<?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); ?>

参考



トップ   編集 凍結 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2021-10-07 (木) 13:33:49 (929d)