Reputation: 889
My PHP file_get_contents() suddenly stopped working. I didn't made any changes, it was running fine before. But from today morning onwards it is getting timeout and my server is throwing bad gateway error.
I checked the same thing through command prompt using curl, it is working fine. Something is wrong with php.
Upvotes: 2
Views: 887
Reputation: 889
I solved the problem by forcing file_get_contents() to use IPV4. It seems like it was trying through IPV6 which does not having internet connection.
$options = array(
'socket' => array(
'bindto' => '0:0'
),
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => http_build_query($data)
)
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
Thanks.
Upvotes: 5