Problem w/ fopen

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
kevdude
Forum Newbie
Posts: 3
Joined: Sat Jun 15, 2002 11:30 pm

Problem w/ fopen

Post by kevdude »

Hello:

I'm having difficulties with the following. I'm using Windows 98 with the latest Apache and PHP:

if(!($myFile=fopen('http://www.fborfw.com/strip_fix/','r')))
{
echo "Sorry, the FBorFW strip is under maintenance.";
exit;
}

The following error is returned:

Warning: php_hostconnect: connect failed in c:\program
files\apache group\apache\htdocs\test1.php on line 14
Warning: fopen("http://www.fborfw.com/strip_fix/", "r") - Bad
file descriptor in c:\program files\apache
group\apache\htdocs\test1.php on line 14

The strange thing is, this works fine on Windows 2000. Anyone have any clues?

Thanks
User avatar
fatal
Forum Contributor
Posts: 118
Joined: Sat Apr 20, 2002 10:47 am
Location: East Coast

Post by fatal »

Since your on localhost, use 'c:\ect...'' to get the file.
kevdude
Forum Newbie
Posts: 3
Joined: Sat Jun 15, 2002 11:30 pm

Post by kevdude »

Yes, I have no problem using fopen for local html files on my c drive. But I would like to grab a URL from a website (as in the example I gave), not a local file on my c drive.

(Typing in http://localhost/test1.php in my browser accesses c:\program files\apache group\apache\htdocs\test1.php.)

What is strange is that I'm able to open the html page from the website I want (referenced in my php code) on a Win2k machine with the same Apache and PHP configurations. Why would it behave differently on a Win98 machine?
User avatar
phphead
Forum Newbie
Posts: 12
Joined: Tue May 28, 2002 11:03 pm
Location: California

INI

Post by phphead »

in php.ini do you have allow url-fopen set to on
kevdude
Forum Newbie
Posts: 3
Joined: Sat Jun 15, 2002 11:30 pm

Post by kevdude »

Yes, it's set as follows:
allow_url_fopen=On
User avatar
falco
Forum Newbie
Posts: 2
Joined: Tue Jul 16, 2002 6:17 am
Location: Hungary
Contact:

Too

Post by falco »

I've got the same problem.

The allow_url_fopen is On.

The server's parameters:
Version: PHP 4.0.6
System: Linux porky.devel.redhat.com 2.4.18-0.1smp #1 SMP Wed Feb 27 07:25:23 EST 2002 i686 unknown
WEB-Server: Apache 1.3.22

It seems to be a bug? :cry:
User avatar
Wayne
Forum Contributor
Posts: 339
Joined: Wed Jun 05, 2002 10:59 am

Post by Wayne »

Code: Select all

if(!($myFile=fopen('http://www.fborfw.com/strip_fix/','r')))
maybe Im missing something, but where is the file you are trying to open? I only see the directory path. Surely you wanted to mention a file after /strip_fix/ ??????
User avatar
falco
Forum Newbie
Posts: 2
Joined: Tue Jul 16, 2002 6:17 am
Location: Hungary
Contact:

Post by falco »

:D

Yes, he really forgot the filename, but for me still don't works:

Code: Select all

$file = file('http://weather.noaa.gov/pub/data/observations/metar/stations/LHBP.TXT');
:(

When i try to open the file from a browser, I get it normally.
User avatar
musashi
Forum Commoner
Posts: 39
Joined: Tue Jul 23, 2002 12:51 pm
Location: Santa Cruz - CA

On FreeBSD

Post by musashi »

I am sure that Falco's code is correct. His example works for me as follows:

Code: Select all

<?php
$file = file('http://weather.noaa.gov/pub/data/observations/metar/stations/LHBP.TXT');
print_r($file);
?>
I get back the array output from the LHBP.TXT file. I would suggest checking out the PHP setup in the php.ini file. It is possible it is a compiler problem, but it does work on FreeBSD using php v. 4.2.2
Post Reply