Remote fopen fails...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Todd_Z
Forum Regular
Posts: 708
Joined: Thu Nov 25, 2004 9:53 pm
Location: U Michigan

Remote fopen fails...

Post by Todd_Z »

Code: Select all

$hnd = fopen( "http://www.alexa.com", "rb" );
yields

Code: Select all

ї09-Jun-2005 16:58:29] PHP Warning: fopen(http://www.alexa.com): failed to open stream: Connection refused in **********************/test.php on line 7
ї09-Jun-2005 16:58:29] PHP Warning: fread(): supplied argument is not a valid stream resource in ***********************/test.php on line 9
an ini_get_all() shows me:

Code: Select all

їallow_url_fopen] => Array
        (
            їglobal_value] => 1
            їlocal_value] => 1
            їaccess] => 4
        )
Any idea why this is? *fsockopen fails too*
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post by anjanesh »

Works here

Code: Select all

<?php
$hnd = fopen("http://www.alexa.com", "rb");
$contents = '';
while (!feof($hnd)) {
  $contents .= fread($hnd, 8192);
}
echo $contents;
fclose($hnd);
?>
User avatar
Todd_Z
Forum Regular
Posts: 708
Joined: Thu Nov 25, 2004 9:53 pm
Location: U Michigan

Post by Todd_Z »

Theres something screwed up with my server, I know my code is correct.
Syranide
Forum Contributor
Posts: 281
Joined: Fri May 20, 2005 3:16 pm
Location: Sweden

Post by Syranide »

If it isn't your server outbound connections might have been blocked.
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

anjanesh wrote:Works here

Code: Select all

<?php
$hnd = fopen("http://www.alexa.com", "rb");
$contents = '';
while (!feof($hnd)) {
  $contents .= fread($hnd, 8192);
}
echo $contents;
fclose($hnd);
?>
i tried a code practically identical yesterday as a test for my EzThumb class, as i have to seperate ways of reading local and remote files, this code basically just created an infinite loop.

I have also seen this code recommended in the PHP manual, som im not sure why it wont work for some people
User avatar
Todd_Z
Forum Regular
Posts: 708
Joined: Thu Nov 25, 2004 9:53 pm
Location: U Michigan

Post by Todd_Z »

How are outbound connections blocked, and how do i lift this block?
Post Reply