Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP5 giving failed to open stream: HTTP request failed error when using fopen

Tags:

php

fopen

This problem seems to have been discussed in the past everywhere on google and here, but I have yet to find a solution.

A very simple fopen gives me a

PHP Warning: fopen(http://www.google.ca): failed to open stream: HTTP request failed!".

The URL I am fetching have no importance because even when I fetch http://www.google.com it doesnt work. The exact same script works on different server. The one failing is Ubuntu 10.04 and PHP 5.3.2. This is not a problem in my script, it's something different in my server or it might be a bug in PHP.

I have tried using a user_agent in php.ini but no success. My allow_url_fopen is set to On.

If you have any ideas, feel free!

like image 466
mickey Avatar asked Jan 05 '11 20:01

mickey


1 Answers

It sounds like your configuration isn't allowed to use file functions, which is common these days because of security concerns. If you have the cURL libraries available to you, I would recommend trying those out.

PHP: cURL

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://www.google.ca/");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$file = curl_exec($ch);
curl_close($ch);

echo $file;
like image 131
Michael Irigoyen Avatar answered Oct 09 '22 12:10

Michael Irigoyen