/    Sign up×
Community /Pin to ProfileBookmark

grabbing an xml file (url) to use locally, seems to fail?

[COLOR=DarkOliveGreen][B]grabbing an xml file (url) to use locally, seems to fail?[/B]

hi,

i’m trying to grab an xml file [url]http://www.bbc.co.uk/syndication/feeds/news/ukfs_news/world/rss091.xml[/url] to use locally.

on my locahost either of the lines below work, np.

when i upload to my hosted site, they don’t!

the browser seems to take slightly longer and it [i]looks[/i] like a time-out, tho rather short…

any ideas?

i.e. are there better methods than copy() or fopen() for this job?

cheers,
bill
[/COLOR]

// copy()
if (!$result = @copy(“http://www.bbc.co.uk/syndication/feeds/news/ukfs_news/world/rss091.xml“, “rss.xml”))
echo (“<br />unable to get file, exiting…<br />”);

// fopen()
$fp=@fopen(“http://www.bbc.co.uk/syndication/feeds/news/ukfs_news/world/rss091.xml“, “rb”);
if (!$fp) echo (“unable to open stream”);

to post a comment
PHP

8 Comments(s)

Copy linkTweet thisAlerts:
@NogDogApr 17.2006 — First I'd try them without the "@" error suppression, and see if you get any error messages that give you more info. It could be a case of your servers not have [url=http://us3.php.net/manual/en/ref.filesystem.php#ini.allow-url-fopen]allow_url_fopen[/url] enabled.
Copy linkTweet thisAlerts:
@hitecbillauthorApr 17.2006 — [COLOR=DarkOliveGreen]hi NogDog,



ok, i did that just to make it tidier...



it says "connection refused"?[/COLOR]


[COLOR=DarkRed]Warning: copy(http://www.bbc.co.uk/syndication/feeds/news/ukfs_news/world/rss091.xml): failed to open stream: Connection refused in /var/www/html/t1.php on line 12



unable to get file, exiting...



Warning: fopen(http://www.bbc.co.uk/syndication/feeds/news/ukfs_news/world/rss091.xml): failed to open stream: Connection refused in /var/www/html/t1.php on line 16

unable to open stream[/COLOR]
Copy linkTweet thisAlerts:
@chazzyApr 17.2006 — As per NogDog:

It could be a case of your servers not have [url=http://us3.php.net/manual/en/ref.filesystem.php#ini.allow-url-fopen]allow_url_fopen[/url] enabled.[/QUOTE]

Have you verified this parameter?
Copy linkTweet thisAlerts:
@NogDogApr 17.2006 — As per NogDog:



Have you verified this parameter?[/QUOTE]

You can do a quick test via:
[code=php]
if(ini_get("allow_url_fopen"))
{
echo "allow_url_fopen is enabled";
}
else
{
echo "allow_url_fopen is not enabled, thus our problem.";
}
[/code]
Copy linkTweet thisAlerts:
@hitecbillauthorApr 17.2006 — ok, tried that, it came back positive...

i emailed my hoster, just in case, he replied "I will enable your account to use outside connections on port 80."...

but thats the web port anyway?

works a treat locally...i think that "connection refused" is the big clue...

cheers,

bill
Copy linkTweet thisAlerts:
@chazzyApr 17.2006 — outbound on port 80. web servers use port 80 inbound. they could block it at the apache level, easier to give out to those you want only.
Copy linkTweet thisAlerts:
@hitecbillauthorApr 19.2006 — well, the port connect thingy was it!


thanks for the backup, chaps. (NogDog and chazzy)


just as a footnote, in this operation, what would be the better way to grab an xml file, [B]copy()[/B] or [B]fopen()[/B] ?

i was thinking that maybe copy() would be better as it grabs the whole file in one go, rather than fgets, line at a a time, over a connection?

also with copy, one gets a local copy, so if, for exmaple, i setup a file date check, so if the file was today's, then simply use the same file, then that would also mean faster loading times, even if, content only updated daily, rather than each run time...

cheers,

bill
Copy linkTweet thisAlerts:
@Stephen_PhilbinApr 19.2006 — The best method of all would be to use
[code=php]
$document = new domDocument();

$document->load("url/to/file.xml");
[/code]

But you'd need PHP 5 to do that.

For future reference, another reason you might be refused a document from another web server would be that you are not sending enough http request headers. I've come across a few Microsoft servers that will refuse your request unless you send them certain headers such as user agent or accept. They don't have to be even close to accurate though, they just have to be there. "user agent: Barry the adventurous beaver ver. 0.1" for example, is a perfectly acceptable browser. (Bet that one'd stick out in their logs eh. ? )
×

Success!

Help @hitecbill 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 4.29,
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: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

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