I
I
issssrt2021-10-20 18:11:47
PHP
issssrt, 2021-10-20 18:11:47

Why did file_get_contents stop working?

I have a small script, the essence of which is to use file_get_contents to collect data from one third-party site.
Everything worked fine, but today a third-party site updated its ssl certificate from lets'en crypt on schedule, and my script returns an error:

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


I tried to run my script on another server (which has never accessed a third-party site) and the script worked properly.

I suppose that I need to clear the cache somewhere on my server?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
alexalexes, 2021-10-20
@issssrt

Try using the more flexible stream_context_create options as one of the parameters to the file_get_contents function. Try 'verify_peer' => false.

$url = 'https://secure.example.com/test/1';
$contextOptions = array(
    'ssl' => array(
        'verify_peer'   => true,
        'cafile'        => __DIR__ . '/cacert.pem',
        'verify_depth'  => 5,
        'CN_match'      => 'secure.example.com'
    )
);
$sslContext = stream_context_create($contextOptions);
$result = file_get_contents($url, NULL, $sslContext);

Source .

V
Vitaly Karasik, 2021-10-20
@vitaly_il1

IMHO, most likely you need to update the system, since you have an outdated Letsencrypt root cert ( https://techcrunch.com/2021/09/21/lets-encrypt-roo... ).
As far as I understand, these are RPM ca-certificates.

T
ThunderCat, 2021-10-20
@ThunderCat

Since October 1, letsencrypt has changed the root certificate, update your version.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question