From: Janusz Dobrowolski Date: Thu, 12 Feb 2009 17:42:24 +0000 (+0000) Subject: Fix for some buggy curl versions. X-Git-Tag: v2.4.2~19^2~1542 X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=commitdiff_plain;h=19b77e12bf5c056e3141032c62cc8d9ad7a21d6e;p=fa-stable.git Fix for some buggy curl versions. --- diff --git a/gl/includes/db/gl_db_rates.inc b/gl/includes/db/gl_db_rates.inc index ab184834..1355e1b7 100644 --- a/gl/includes/db/gl_db_rates.inc +++ b/gl/includes/db/gl_db_rates.inc @@ -74,20 +74,28 @@ function delete_exchange_rate($rate_id) function get_ecb_rate($curr_b) { $curr_a = get_company_pref('curr_default'); - $ecb_filename = 'http://www.ecb.int/stats/eurofxref/eurofxref-daily.xml'; + $ecb_filename = '/stats/eurofxref/eurofxref-daily.xml'; + $ecb_site = 'www.ecb.int'; $contents = ''; if (function_exists('curl_init')) { // first check with curl as we can set short timeout; - $ch = curl_init(); - curl_setopt ($ch, CURLOPT_URL, $ecb_filename); - curl_setopt ($ch, CURLOPT_COOKIEJAR, "cookie.txt"); - curl_setopt ($ch, CURLOPT_HEADER, 0); - curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); - curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1); - curl_setopt ($ch, CURLOPT_TIMEOUT, 5); - $contents = curl_exec ($ch); - curl_close($ch); + $retry = 1; + do { + $ch = curl_init(); + curl_setopt ($ch, CURLOPT_URL, 'http://'.$ecb_site.$ecb_filename); + curl_setopt ($ch, CURLOPT_COOKIEJAR, "cookie.txt"); + curl_setopt ($ch, CURLOPT_HEADER, 0); + curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); + curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1); + curl_setopt ($ch, CURLOPT_TIMEOUT, 3); + $contents = curl_exec ($ch); + curl_close($ch); + // due to resolver bug in some curl versions (e.g. 7.15.5) + // try again for constant IP. + $ecb_site="195.128.2.97"; + } while( ($contents == '') && $retry--); + } else { $handle = @fopen($ecb_filename, 'rb'); if ($handle) { diff --git a/gl/manage/exchange_rates.php b/gl/manage/exchange_rates.php index 02ba10c7..493509f9 100644 --- a/gl/manage/exchange_rates.php +++ b/gl/manage/exchange_rates.php @@ -135,9 +135,6 @@ function display_rate_edit() if (isset($_POST['get_rate'])) { $_POST['BuyRate'] = exrate_format(get_ecb_rate($_POST['curr_abrev'])); - if ($_POST['BuyRate'] == 0) { - display_error(_('This currency is not listed by ECB. Enter exchange rate manually.')); - } $Ajax->activate('BuyRate'); } small_amount_row(_("Exchange Rate:"), 'BuyRate', null, '',