Tiberiu-IonuČ› Stan Tiberiu-IonuČ› Stan - 7 months ago 220
PHP Question

file_get_contents ignoring verify_peer=>false?

file_get_contents with https hosts works just fine, except for a particular host (test api server from some company - ip whitelisted, can't give you URL to test). This rules out not loaded https modules and other initial setup mistakes.

I have tested with multiple PHP installations, all at v5.3.3, 32bits, Debian 32bits.

The request works with cURL, but only if setting

. However, setting
on the context for file_get_contents seems to make no difference.

With file_get_contents, the exact same request (same URL, same XML POST data) fails with SSL: Connection reset by peer:

"http" => array(
"method" => "POST",
"header" =>
"Content-Type: application/xml; charset=utf-8;\r\n".
"Connection: close\r\n",
"ignore_errors" => true,
"timeout" => (float)30.0,
"content" => $strRequestXML,

file_get_contents("https://somedomain:2000/abc/", false, stream_context_create($arrContextOptions));


Has anyone encountered this with file_get_contents? Any ideas how to debug?


try this code :

$fp = fsockopen("ssl://somedomain/abc/", 2000 , $ErrNo, $ErrString, 30);
if (!$fp) {
    echo "Error No : $ErrNo - $ErrString <br />\n";
} else {
    $out  = "POST / HTTP/1.1\r\n";
    $out .= "Host: somedomain \r\n";
    $out .= "Content-Type: application/xml; charset=utf-8;\r\n";
    $out .= "Connection: Close\r\n\r\n";
    fwrite($fp, $out);
    while (!feof($fp)) {
        echo fgets($fp, 128);

if you don't get error , i think problem (with file_get_contents) is form client php configuration otherwise from server configuration.