Forum Moderators: coopster

Message Too Old, No Replies

PHP - fopen() trouble?

         

Nick_W

1:13 pm on Feb 1, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



$f=fopen("http://www.site.com/index.php", "r");

Is producing this:

Warning: php_network_getaddresses: getaddrinfo failed: Name or service not known in /var/www/html/ test.com/test.php on line 2

Warning: fopen("http://wwww.site.com/index.php", "r") - Bad file descriptor in /var/www/html/test.com/ test.php on line 2

Anyone have the faintest idea what I'm doing wrong?

andreasfriedrich

1:23 pm on Feb 1, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Are you able to access the URL from the server the script is running on?

Did you allow http to be used by fopen?

Andreas

Nick_W

1:26 pm on Feb 1, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Not certain of either Andreas.

Which directive controls http and how can I test if I can access from my server?

Thanks ;)

Nick

andreasfriedrich

1:32 pm on Feb 1, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



allow_url_fopen [php.net]

From the console do a

telnet www.site.com 80
. This will connect to site on port 80. Then when the server responds type
GET /path/to/doc HTTP/1.0
and press enter twice.

Alternatively you could use wget [site.com...] or lynx [site.com...] or any other of a thousand different methods I canīt think of right now.

If you are running a GUI on the server you could use your favorite browser as well. Just make sure that it will access the site the same route the script will. (No proxy in browser while script uses direct access).

HTH Andreas

Nick_W

2:21 pm on Feb 1, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hmmmm.. thanks Andreas

Telnet -> fine
allow_url_fopen = On

Any idea what else it could be?

[pre]
<?
$open=fopen("http://wwww.site.com/index.php", "r");
$file=readfile($open);
print($file);
?>[/pre]

Nick

andreasfriedrich

2:41 pm on Feb 1, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



readfile [php.net] takes a filename as its first argument not a file pointer. It then sends the file directly to STDOUT. $file will not contain the file but the number of bytes read by readfile. Just use the URI as the filename.

Alternatively use fopen and then a f* variant to read the file into a variable. Remember, when you fopen you fread, you fwrite, you fclose, etc.

php.net is your friend, Nick ;)

Andreas

Nick_W

2:52 pm on Feb 1, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I know, I know.....

I'll try again but the error comes from fopen so wether i'm using readfile() correctly or not does not appear to be the issue? -- I'll go try again though and make sure I'm doing everything correctly :)

Nick

andreasfriedrich

3:12 pm on Feb 1, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You could try using fsockopen [php.net] to connect to the site and then talk HTTP with it. This will at least tell you whether PHP is able to make a connection at all.

Nick_W

4:31 pm on Feb 1, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Okay, i'm an idiot. I admit it freely and, unconditionally.

wwww.site.com was what I was trying to open.

What a pillock :(

Thanks for the help Andreas, sorry it was a wild goose chase ;)

Nick

andreasfriedrich

4:41 pm on Feb 1, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Too bad that those folks at Site Services, Inc. obviously do not want us to see whatīs there at www.site.com ;)

I like to use a well known site for testing ;)

Perhaps WebmasterWorld should allow posting of URLs because then you would not edit out the URI you were actually using and then paste it back into your program and get confused about the whole thing.

Anyway, glad you got is sorted out.

Andreas