今天再开发时,发现利用file_get_content() 获取https的文件内容时,获取不到内容,会报ssl 错误
file_get_contents(): SSL operation failed with code 1. OpenSSL Error messages:\nerror:1416F086:SSL routines:tls_process_server_certificate:certificate verify failed
查了相关资料,解决方法,如下,即去掉 file_get_contents() 函数的证书校验
$opts = [ "ssl" => [ "verify_peer"=>false, "verify_peer_name"=>false, ] ]; $response = file_get_contents("https://www.example.com",false, stream_context_create($opts));