failed to open stream: HTTP request failed

chris.cohen - September 3, 2008 - 11:58
Project:Ad GeoIP
Version:6.x-2.0-rc1
Component:Code
Category:bug report
Priority:minor
Assigned:Unassigned
Status:postponed
Description

This is a very strange issue that I don't think is caused by a bug in the Ad GeoIP module, but it directly affected it for me, and so hopefully this might help anyone else in the same situation. The problem is caused when line 461 of ad_geoip.module is executed:

<?php
$codes
= file($url);
?>

This triggers a timeout because PHP fails to request the http://www.iso.org/iso/iso3166_en_code_lists.txt URL. I checked that this line is present in my php.ini file:

allow_url_fopen = On

I checked that I could retrieve the document with:

lynx -source http://www.iso.org/iso/iso3166_en_code_lists.txt

...I also changed the user_agent in php.ini from 'PHP' to mimic both Internet Explorer 6 and Firefox 2, but none of this made any difference.

I could not diagnose the problem at all, but it appears to be similar to that described in this post. I used the suggested solution there, which is using curl to get the file instead of PHP's built-in method. This is my replacement:

<?php
  
// url for latest iso3166 list of two-character country codes.
 
$url = 'http://www.iso.org/iso/iso3166_en_code_lists.txt';
 
$temp_path = '/tmp/temp_codes.txt';

   
// Grab the XML and save it to a temporary file. This method replaces the
    // usual call to file() with a curl-based method.
   
$ch = curl_init($url);
   
$fp = fopen($temp_path, "w");
   
curl_setopt($ch, CURLOPT_FILE, $fp);
   
curl_setopt($ch, CURLOPT_HEADER, 0);
   
curl_exec($ch);
   
curl_close($ch);
   
fclose($fp);

 
// load list into an array.
 
$codes = file($temp_path);
?>

#1

Jeremy - April 17, 2009 - 16:28
Version:5.x-1.1-1» 6.x-2.0-rc1
Status:active» postponed

I'd be interested in a patch that optionally uses curl if it's available, but I'd like to avoid adding this as a required dependency. Postponed, waiting for a patch (for the latest development version).

 
 

Drupal is a registered trademark of Dries Buytaert.