By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,490 Members | 1,489 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,490 IT Pros & Developers. It's quick & easy.

Can not open url using fopen or file

P: n/a
Hi

I have a problem in opening url using 'file'.
I searched many other discussion groups and tried suggestions,
but could not resolve this problem.
e.g

<?php
$myfile = file('http://google.com');
foreach ( $myfile as $vals){
print "$vals";
}
?>

I got an error: failed to open stream: Permission denied.

The above script works on my windows pc, but does not work on Linux
(Fedora 5, php v5.1.2). I found there was no difference between windows
php.ini and linux php.ini. But it does not work on the Linux web
browser. I also tested with fopen and fsockopen, but did not work.
allow_url_fopen was set to On.

I did some other tests:
1. % php -f /var/www/index.html // works on the linux command line
// each of the following three lines was tested in the above script.
2. file('/var/www/index.html'); // this works on the Linux web browser.
3. file('http://localhost/index.html'); // failed to open stream:
permission denied.
4. file('http://google.com'); // failed to open stream: permission denied.

Any possibility for firewall (internet works fine) or other
configuration issues?

Could anyone can help me please?

bk
Sep 8 '07 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Brian wrote:
Hi

I have a problem in opening url using 'file'.
I searched many other discussion groups and tried suggestions,
but could not resolve this problem.
e.g

<?php
$myfile = file('http://google.com');
foreach ( $myfile as $vals){
print "$vals";
}
?>

I got an error: failed to open stream: Permission denied.

The above script works on my windows pc, but does not work on Linux
(Fedora 5, php v5.1.2). I found there was no difference between windows
php.ini and linux php.ini. But it does not work on the Linux web
browser. I also tested with fopen and fsockopen, but did not work.
allow_url_fopen was set to On.

I did some other tests:
1. % php -f /var/www/index.html // works on the linux command line
// each of the following three lines was tested in the above script.
2. file('/var/www/index.html'); // this works on the Linux web browser.
3. file('http://localhost/index.html'); // failed to open stream:
permission denied.
4. file('http://google.com'); // failed to open stream: permission denied.

Any possibility for firewall (internet works fine) or other
configuration issues?

Could anyone can help me please?

bk
It could be a firewall. It could also be your php.ini. Are you sure
you compared the ones PHP is using? Check it with phpinfo().

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Sep 8 '07 #2

P: n/a
Brian wrote:
>
>>
It could be a firewall. It could also be your php.ini. Are you sure
you compared the ones PHP is using? Check it with phpinfo().

I just installed Fedora 5 and did not change any firewall setting.

Below is the results of phpinfo generated from my Linux.
<snip lots of settings>

OK, have you done any analysis on this at all? For instance, have you
compared the failing phpinfo() output with the working one?

Does it match what you see in your php.ini file?

Interestingly enough I don't see the location of the php.ini file it's
using - or a lot of other information normally put out by php...

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Sep 8 '07 #3

P: n/a
Brian wrote:
Yes I compared phpinfo with the working one.
I did not find any thing that causes the problem.
I just greped the actual configuration part and removed the comments.
php.ini is in /etc/
The full list is:
<snip>

OK, thanks - that helps a lot.

I don't see anything wrong with the PHP settings; it should work just
fine from the PHP end. And BTW - it's also parsing several files in
your /etc/php.d directory, but I don't see anything causing a problem
off hand.

So this leaves a couple of possibilities: you have a firewall on your
system blocking outbound access, or you can't get the page itself -
either because the page is unavailable or they have blocked your IP
address. But google shouldn't be blocking you - is it in fact google
you're trying to access? Or did you just use google for an example?

If you are trying to retrieve from google. chances are it's a firewall
issue. But if you used google as an example, you might be blocked. In
that case you could try a different site (like google) to see if it works.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Sep 8 '07 #4

P: n/a
On Sat, 08 Sep 2007 01:46:20 GMT, Brian <dk***@bigpond.net.auwrote:
>$myfile = file('http://google.com');
I got an error: failed to open stream: Permission denied.

The above script works on my windows pc, but does not work on Linux
(Fedora 5, php v5.1.2). I found there was no difference between windows
php.ini and linux php.ini. But it does not work on the Linux web
browser. I also tested with fopen and fsockopen, but did not work.
allow_url_fopen was set to On.

I did some other tests:
1. % php -f /var/www/index.html // works on the linux command line
// each of the following three lines was tested in the above script.
2. file('/var/www/index.html'); // this works on the Linux web browser.
3. file('http://localhost/index.html'); // failed to open stream:
permission denied.
4. file('http://google.com'); // failed to open stream: permission denied.

Any possibility for firewall (internet works fine) or other
configuration issues?
Fedora uses SELinux by default doesn't it? It may be restricting what the
Apache worker processes can do under that user ("apache" or "nobody" or
whatever).

See if this helps: http://docs.fedoraproject.org/selinux-faq-fc5/

--
Andy Hassall :: an**@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
Sep 8 '07 #5

P: n/a
Jerry,
If you are trying to retrieve from google. chances are it's a firewall
issue.
You are RIGHT!. Firewall blocked it. I found the solution.
In Fedora 5, there is System->Administration->Security Level and
Firewall->SELinux.

If SELinux is enabled, it does not work.
If SELinux is disabled or permissive, it works.

I really appreciate your help.

Brian

Sep 8 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.