azure-storage-php: PHP Fatal Error: fopen(): Failed to enable crypto

Hello,

I have a Windows Web App service running PHP 7.2. The Web App has PHP code that reads data from Azure Blob Storage. My code to do this is based on the examples given in this repo.

Everything seems to be working properly during our testing. However, once we start adding web traffic load to the Web App (by running an Azure Performance Test or other external load), the PHP error logs start filling up with the below error. IIS throws a Internal Server Error as well.

This is confusing because it works perfectly fine during testing. One thought I had was because the errors below point to openssl, it may be a lack of randomness available to generate https connections to the Azure Blob Service. However, this is just a speculation on my part.

Thank you!

   [02-Apr-2018 10:45:35 America/New_York] PHP Fatal error:  Uncaught RuntimeException: Error creating resource: [message] fopen(): SSL operation failed with code 1. OpenSSL Error messages:
   error:1416F086:SSL routines:tls_process_server_certificate:certificate verify failed 
   [file] D:\home\site\wwwroot\vendor\guzzlehttp\guzzle\src\Handler\StreamHandler.php
   [line] 324
   [message] fopen(): Failed to enable crypto
   [file] D:\home\site\wwwroot\vendor\guzzlehttp\guzzle\src\Handler\StreamHandler.php
   [line] 324
   [message] fopen(https://XXXX.blob.core.windows.net/YYYY/ZZZZ): failed to open stream: operation failed
   [file] D:\home\site\wwwroot\vendor\guzzlehttp\guzzle\src\Handler\StreamHandler.php
   [line] 324 in D:\home\site\wwwroot\vendor\guzzlehttp\guzzle\src\Handler\StreamHandler.php:252
   Stack trace:
   #0 D:\home\site\wwwroot\vendor\guzzlehttp\guzzle\src\Handler\StreamHandler.php(335): GuzzleHttp\Handler\StreamHandler->createResource(Object(Closure))
   #1 D:\home\site\wwwroot\vendor\guzzlehttp\guzzle\src\Handler\StreamHandler.php(52): GuzzleHtt in D:\home\site\wwwroot\vendor\guzzlehttp\guzzle\src\Exception\RequestException.php on line 52

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 16 (8 by maintainers)

Most upvoted comments

Hi @XiaoningLiu,

This issue seemed to be solved by caching the data from Azure Blob Storage. I believe that when website traffic starts to increase, either PHP’s openssl/crypto libraries or something in the Azure libraries becomes overwhelmed and starts throwing this error. I used WinCache’s User Cache API to cache the Azure Blob Storage data for 10 seconds. A quick example of my code:

$data = wincache_ucache_get('myKey', $success); // Try to fetch from cache
if (false === $success) {
    // Data not  found in cache; fetch from Azure Blob Storage into $data

    // -- code removed --

    wincache_ucache_set('myKey', $data, 10); // Put data in cache with TTL of 10 seconds
}

echo $data; // Send data to the HTTP client

We are still testing this, however so far, this caching in PHP for 10 seconds seemed to alleviate the load and solved this issue.

Thank you! Steve