http_get() question

ok, another project!

We recently started getting rate exchange info from xe.com, but to get that info, they’re support says to use http_get, but, with php 5.3, it doesn’t seem to be supported (or its not installed). I looked at the phpinfo and didn’t see it in there anywhere. Since godaddy doesn’t know anything about supporting their customers, is there an alternate way of doing that type of request?

did you install the pecl_http PHP extension
oh sorry

godaddy

yea, i can’t install it. They upgraded the verison of php and broke everyone’s cron job scripts because the new version depreciated get magic quotes. Their fix was to have me put a php.ini in my root folder, but since i’m on a shared hosting plan, it would have no effect what so ever. Tried to tell them that, but given that they have no knowledge of php or mysql, i figured it out myself and fixed it using ini_set().

I think i found another way of doing it using file_get_contents

[php]
$opts = array(‘http’=>array(‘method’=>“GET”,));
$context = stream_context_create($opts);
$file = file_get_contents(‘http://www.xe.com/dfs/datafeed2.cgi?companyname’, false, $context);

$fcontents = $file;[/php]

Seemed to work ok, except xe was returning the wrong file type, but now it doesn’t work after i updated the xe config, guess i’ll have to wait til tomorrow to see the config change worked.

Problem solved. It ended up being XE’s problem. apparently they don’t work on the weekends, so the feed hadn’t been activated yet. Once that was fixed and a few other things were figured out, it worked just fine. This is what i ended up with
[php]<?php
ini_set(“magic_quotes_gpc”, 0);
ini_set(‘auto_detect_line_endings’, true);

// db connection script

$file = file(‘http://url’, FILE_IGNORE_NEW_LINES); //can’t show the real url

for($i = 23; $i < count($file); $i++) {

$line = $file[$i];
$arr = explode(",", $line);

foreach($arr as $key => $value) {
	$arr[$key] = $value;
}

$find = mysql_query("SELECT code FROm xe WHERE code = $arr[0]");

if(mysql_num_rows != 0) {
	$build = "UPDATE xe SET usdrate = $arr[2], backrate = $arr[3] WHERE code = $arr[0]";
} else {
	$build = "INSERT INTO xe (code, country, usdrate, backrate) VALUES (" . implode(", ", $arr). ")";
}

mysql_query($build);

}
?> [/php]

The feed i get has a crap load of useless lines on top, that’s why i start where i do.

Sponsor our Newsletter | Privacy Policy | Terms of Service