|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2021-01-13 18:32 UTC] cmb@php.net
-Status: Open
+Status: Feedback
-Assigned To:
+Assigned To: cmb
[2021-01-13 18:32 UTC] cmb@php.net
[2021-01-13 21:03 UTC] bilge at scriptfusion dot com
-Status: Feedback
+Status: Assigned
[2021-01-13 21:03 UTC] bilge at scriptfusion dot com
[2021-01-14 12:47 UTC] cmb@php.net
-Status: Assigned
+Status: Verified
-Assigned To: cmb
+Assigned To:
[2021-01-14 12:47 UTC] cmb@php.net
[2021-01-14 12:52 UTC] bilge at scriptfusion dot com
[2022-02-28 08:51 UTC] larrybrenda665 at gmail dot com
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 21:00:01 2025 UTC |
Description: ------------ Using file_get_contents() in an object oriented application can be perilous since it emits errors and warnings directly. We would prefer to silence the call, check the return value and if it's false retrieve the error message. e.g. if (false === @file_get_contents(...)) { $error = error_get_last(); }. This strategy works well for HTTP calls but when one throws SSL into the mix the errors returned by error_get_last() are different from the ones emitted directly by file_get_contents(). More specifically, the errors become vague and unhelpful. The real details of the failure can only be seen by removing the silence operator (@) and thus this is the crux of the bug: it is not possible to see SSL errors in an object oriented environment. N.B. Calling openssl_error_string() just returns false. --- For example, the test script below outputs a general failure message such as: "file_get_contents(https://[::1]:6666): failed to open stream: Connection refused" However, since we are using a self-signed certificate, removing the silence operator yields a much more useful error message from OpenSSL: file_get_contents(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed The problem is PHP provides no way to capture this output from OpenSSL. Test script: --------------- if (false === $response = @file_get_contents( 'https://[::1]:6666', false, stream_context_create([ 'http' => ['ignore_errors' => true], ]) )) { echo error_get_last()['message']; // file_get_contents(https://[::1]:6666): failed to open stream: Connection refused var_dump(openssl_error_string()); // bool(false) // We can't see the real error that occurred in the OpenSSL subsystem. }