/    Sign up×
Community /Pin to ProfileBookmark

Webservice is not working on production server.

Hi all,

I am new to this forum but hope you all will help me.

I am trying to call a web service to convert currency. The problem is this when I am calling this web service from my local server its working fine but once I put this php code on my web server. Its not working.

I have cross check with my hosting provider. He is saying everything is working fine.

Can anyone tell me what I need to do and solve this problem.

Many Thanks in advance

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@MindzaiJan 29.2010 — Seriously? You post no code, don't even mention the webservice by name, give no information on software and hardware involved, and you expect us to be able to tell you why it's not working?! We are programmers not psychics! Give us a bit more to go on please.
Copy linkTweet thisAlerts:
@AlokRawatauthorJan 30.2010 — @Mindzai

Sorry for that, I was thinking there is some settings for web server.

So here we go..

I am trying to call http://www.webservicex.net/CurrencyConvertor.asmx web service to convert currency from INR to USD on my localhost. Here everything working fine.

But Once I put it on my apache web server. Here it is not working.

currency_class.php
[code=html]<?php
class JOJO_Currency
{
function getCurrencies()
{
return array(
'NZD' => "New Zealand Dollar",
'USD' => "U.S. Dollar",
'EUR' => "Euro",
'GBP' => "British Pound",
'INR' => "Indian Rupee",
);
}

function getRate($from, $to)
{
return false;
}
}


class JOJO_Currency_webservicex extends JOJO_Currency
{
function getRate($from, $to, $snoopy = true)
{
/* Set the $snoopy option to true to avoid any fopen file security issues on some shared hosts */

$url = sprintf("http://www.webservicex.net/CurrencyConvertor.asmx/ConversionRate?FromCurrency=%s&ToCurrency=%s",
$from,
$to);

if ($snoopy) {
require_once(_PLUGINDIR . "/jojo_convert_currency/external/Snoopy/Snoopy.class.php");
$snoopy = new Snoopy;
$snoopy->fetch($url);
$res = trim(strip_tags($snoopy->results));
} else {
$res = trim(strip_tags(implode('', file($url))));
}
return $res;
}
}

class JOJO_Currency_yahoo extends JOJO_Currency {

function _currency_api_get_desc($currency)
{
foreach ($this->getCurrencies() as $key => $description) {
if ($key == $currency) {
return $description;
}
}
return FALSE;
}

function getRate($currency_from, $currency_to, $snoopy = true)
{
$amount = 1;
$currency_array = array(
's' => 'Currencies',
'l1' => 'Last',
'd1' => 'Date',
't1' => 'Time'
);

$result = array();
$result['status'] = FALSE;
$result['message'] = '';
$result['value'] = '';
$result['date'] = '';
$result['time'] = '';

$from = strtoupper($currency_from);
$to = strtoupper($currency_to);

$url = 'http://finance.yahoo.com/d/quotes.csv?e=.csv&f='. $this->_currency_api_get_fields($currency_array) .'&s='. $from . $to .'=X';

// Validate the passed currency codes, to make sure they are valid
if (FALSE == $this->_currency_api_get_desc($from)) {
$msg = "currency: Invalid currency_from=$from";
$result['message'] = $msg;
$result['status'] = FALSE;
}

if (FALSE == $this->_currency_api_get_desc($currency_to)) {
$msg = "currency: Invalid currency_to=$to";
return FALSE;
$result['message'] = $msg;
$result['status'] = FALSE;
}

if (!is_numeric($amount)) {
$msg = "currency: Invalid amount=$amount";
$result['message'] = $msg;
$result['status'] = FALSE;
}

$handle = @fopen($url, 'r');
if ($handle) {
if ($record = fgets($handle, 4096)) {
fclose($handle);
$currency_data = explode(',', $record);
$rate = $currency_data[1];
$date = $currency_data[2];
$time = $currency_data[3];

// Calculate the result
$value = $amount * $rate;

// Log it

// Got what we need
$result['value'] = $value;
$result['date'] = $date;
$result['time'] = $time;
$result['status'] = TRUE;
$result['message']= 'success';
} else {
$msg = 'currency: fgets failed';
$result['status'] = FALSE;
$result['message'] = $msg;
}
} else {
$msg = 'currency: cannot contact Yahoo Finance host';
$result['status'] = FALSE;
$result['message'] = $msg;
}

return $result['value'];
}


function _currency_api_get_fields($array) {
$field_string = '';
while (list($field, $header) = each($array)) {
$field_string .= $field;
}

return $field_string;
}
}
?>[/code]


index.php

[code=html]<?php
/************* Exchange Rate Calculator *******************/
/*
Released by AwesomePHP.com, under the GPL License, a
copy of it should be attached to the zip file, or
you can view it on http://AwesomePHP.com/gpl.txt
*/
/************* Exchange Rate Calculator *******************/

// Include Class
require_once('currency_class.php');

// Get list of currencies
$c = new JOJO_Currency_yahoo();
$list = $c->getCurrencies();

// Check any submitions
// Amount to convert
$amount = 2000;
// From
$from = 'INR';
// To
$to = 'USD';
// Get rate
$rate = $c->getRate($from,$to, true);
// Total price (to 2 decemial points)
echo $total = number_format(($rate*$amount),2);
//'hi';

?>
[/code]
Copy linkTweet thisAlerts:
@criterion9Jan 30.2010 — What does the Snoopy->fetch() method look like?
×

Success!

Help @AlokRawat spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...