file_get_contents(): SSL operation failed with code 1, Failed to enable crypto

file_get_contents(): ssl operation failed with code 1. openssl error messages: error:14090086
file_get_contents(): failed to enable crypto
message: file_get_contents(): failed to enable crypto
ssl operation failed with code 1 openssl error messages composer
error:1416f086:ssl routines:tls_process_server_certificate:certificate verify failed
error:14090086:ssl routines:ssl3_get_server_certificate:certificate verify failed
failed to open stream: operation failed
php warning: file_get_contents(): ssl operation failed with code 1. openssl error messages:

I’ve been trying to access this particular REST service from a PHP page I’ve created on our server. I narrowed the problem down to these two lines. So my PHP page looks like this:

<?php
$response = file_get_contents("https://maps.co.weber.ut.us/arcgis/rest/services/SDE_composite_locator/GeocodeServer/findAddressCandidates?Street=&SingleLine=3042+N+1050+W&outFields=*&outSR=102100&searchExtent=&f=json");

echo $response; ?>

The page dies on line 2 with the following errors:

  • 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 ...php on line 2
    • Warning: file_get_contents(): Failed to enable crypto in ...php on line 2
    • Warning: file_get_contents(https://maps.co.weber.ut.us/arcgis/rest/services/SDE_composite_locator/GeocodeServer/findAddressCandidates?Street=&SingleLine=3042+N+1050+W&outFields=*&outSR=102100&searchExtent=&f=json): failed to open stream: operation failed in ...php on line 2

We’re using a Gentoo server. We recently upgraded to PHP version 5.6. It was after the upgrade when this problem appeared.

I found when I replace the REST service with an address like https://www.google.com; my page works just fine.

In an earlier attempt I set "verify_peer"=>false, and passed that in as an argument to file_get_contents, as described here: file_get_contents ignoring verify_peer=>false? But like the writer noted; it made no difference.

I’ve asked one of our server administrators if these lines in our php.ini file exist:

  • extension=php_openssl.dll
  • allow_url_fopen = On

He told me that since we’re on Gentoo, openssl is compiled when we build; and it’s not set in the php.ini file.

I also confirmed that allow_url_fopen is working. Due to the specialized nature of this problem; I’m not finding a lot of information for help. Have any of you come across something like this? Thanks.


This was an enormously helpful link to find:

http://php.net/manual/en/migration56.openssl.php

An official document describing the changes made to open ssl in PHP 5.6 From here I learned of one more parameter I should have set to false: "verify_peer_name"=>false

Note: This has very significant security implications. Disabling verification potentially permits a MITM attacker to use an invalid certificate to eavesdrop on the requests. While it may be useful to do this in local development, other approaches should be used in production.

So my working code looks like this:

<?php
$arrContextOptions=array(
    "ssl"=>array(
        "verify_peer"=>false,
        "verify_peer_name"=>false,
    ),
);  

$response = file_get_contents("https://maps.co.weber.ut.us/arcgis/rest/services/SDE_composite_locator/GeocodeServer/findAddressCandidates?Street=&SingleLine=3042+N+1050+W&outFields=*&outSR=102100&searchExtent=&f=json", false, stream_context_create($arrContextOptions));

echo $response; ?>

php 5.6 Warning: file_get_contents(): SSL operation failed with code , php 5.6 Warning: file_get_contents(): SSL operation failed with code 1. OpenSSL Error messages: Warning: file_get_contents(): Failed to enable crypto in. recaptcha not work properly on php 5.6 (php 5.5 work fine) Verify the response string, i got error: Warning: file_get_contents(): SSL operation failed with code 1.


You shouldn't just turn off verification. Rather you should download a certificate bundle, perhaps the curl bundle will do?

Then you just need to put it on your web server, giving the user that runs php permission to read the file. Then this code should work for you:

$arrContextOptions=array(
    "ssl"=>array(
        "cafile" => "/path/to/bundle/cacert.pem",
        "verify_peer"=> true,
        "verify_peer_name"=> true,
    ),
);

$response = file_get_contents("https://maps.co.weber.ut.us/arcgis/rest/services/SDE_composite_locator/GeocodeServer/findAddressCandidates?Street=&SingleLine=3042+N+1050+W&outFields=*&outSR=102100&searchExtent=&f=json", false, stream_context_create($arrContextOptions));

Hopefully, the root certificate of the site you are trying to access is in the curl bundle. If it isn't, this still won't work until you get the root certificate of the site and put it into your certificate file.

file_get_contents(): SSL operation failed #php, Warning: file_get_contents(): SSL operation failed with code 1. OpenSSL Warning: file_get_contents(): Failed to enable crypto in/file.php on line 10. Warning:  I'm getting this issue when trying to install composer. I get around this with the flag --disable-tls when piped to PHP. I still can't run composer update though unless I disable-tls everytime.


I fixed this by making sure that that OpenSSL was installed on my machine and then adding this to my php.ini:

openssl.cafile=/usr/local/etc/openssl/cert.pem

file_get_contents(): SSL operation failed with code 1, file_get_contents(): SSL operation failed with code 1. brahm.pragya. User Warning: file_get_contents(): Failed to enable crypto in  Sometimes xampp or Wamp Server and windows 7, 8, 8.1 or 10 user may face a unwanted problem when installing PHP Composer. You may familiar with the following


You can get around this problem by writing a custom function that uses curl, as in:

function file_get_contents_curl( $url ) {

  $ch = curl_init();

  curl_setopt( $ch, CURLOPT_AUTOREFERER, TRUE );
  curl_setopt( $ch, CURLOPT_HEADER, 0 );
  curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
  curl_setopt( $ch, CURLOPT_URL, $url );
  curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, TRUE );

  $data = curl_exec( $ch );
  curl_close( $ch );

  return $data;

}

Then just use file_get_contents_curl instead of file_get_contents whenever you're calling a url that begins with https.

file_get_contents SSL operation failed with code 1 , file_get_contents SSL operation failed with code 1 SSL3_GET_SERVER_CERTIFICATE certificate verify failed. This is caused by PHP being unable to verify the certificate as the message says! The reason why it can't verify the certificate is almost certainly related to file certificate authorities file (aka the CA file). Check your openssl version, and try to upgrade it in case it is a version not supporting TLS 1.2. There is nothing Composer can do there, as it is not implementing the TLS encryption itself (this is done at the PHP layer using the Openssl extension)


If your PHP version is 5, try installing cURL by typing the following command in the terminal:

sudo apt-get install php5-curl

Failed to generate PDF: file_get_contents(): SSL operation failed , Failed to generate PDF: file_get_contents(): SSL operation failed with code 1 Code. Priority: Normal. Category: Bug report. Assigned: Unassigned. Reporter: I get the following error after enabling the module and heading to /entityprint/​node/1: verify failed, file_get_contents(): Failed to enable crypto,  Following the installer instructions, and running php composer-setup.php after Installer was verified, this was output: All settings correct for using Composer Warning: file_get_contents(): SSL operation failed with code 1.


ICU-Bariatric SMART Rollboard, Order-No: 110.0200. Warning: file_get_contents(): SSL operation failed with code 1. OpenSSL Error Warning: file_get_contents(): Failed to enable crypto in  file_get_contents (): SSL operation failed with code 1, Failed to enable crypto. Asked 5 years, 2 months ago. Active 1 month ago. Viewed 251k times. I’ve been trying to access this particular REST service from a PHP page I’ve created on our server. I narrowed the problem down to these two lines. So my PHP page looks like this:


Our Blog Posts, Warning: file_get_contents(): SSL operation failed with code 1. OpenSSL Error messages: Warning: file_get_contents(): Failed to enable crypto in  The core issue is just that yesterday I merged his PR to do properly verified SSL (as opposed to stock PHP SSL which really only checks SSL is in use but doesn't check the certificate matches anything).


Retail-2 slider Archives, Search. Warning: file_get_contents(): SSL operation failed with code 1. OpenSSL Error messages: Warning: file_get_contents(): Failed to enable crypto in