php – simplexml_load_file – Warning: simplexml_load_file(): SSL operation failed with code 1.

Od posmura

Error message:

Warning: simplexml_load_file(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed…

Solution:

  1. Download: ca-bundle.crt.
  2. Update code:
 const URL = "https://service.domain.xy?";
 const CA_FILE = "c:/php/cert/ca-bundle.crt";

 private function loadXml(string $value1, string $value2)
    {
        $streamContent = stream_context_get_default([
            'http' => ['proxy' => $this->proxy, 'request_fulluri' => true],
            'ssl' => ['verify_peer' => true,'cafile' => self::CA_FILE],
        ]);
        libxml_set_streams_context($streamContent);
        return simplexml_load_file(self::URL . "param1=" . $value1 . "&param2=" . $value2);
    }