file_get_contents('https://invalid-certificate.com');
產生以下PHP警告和錯誤:如何獲取file_get_contents()警告而不是PHP錯誤?
PHP warning: Peer certificate CN='*.invalid-certificate.net' did not match expected CN='invalid-certificate.com'
PHP error: file_get_contents(https://invalid-certificate.com): failed to open stream: operation failed
我想用異常而不是PHP的警告,所以:
$response = @file_get_contents('https://invalid-certificate.com');
if ($response === false) {
$error = error_get_last();
throw new \Exception($error['message']);
}
但現在的異常消息是:
file_get_contents(https://invalid-certificate.com): failed to open stream: operation failed
這是正常的,error_get_last()
回報的最後一個錯誤 ...
我怎樣才能得到警告,其中包含有關失敗的許多有價值的信息?
捲曲最好是處理錯誤而不是'file_g et_contents()' – 2015-03-02 04:56:50
@jogesh_pi是的我知道,我想知道'file_get_contents()'。 – 2015-03-02 05:02:21