473,382 Members | 1,635 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Can not open url using fopen or file

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
5 15533
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Cam | last post by:
Hi I'm using this simple rss parser that i would like to have open in another window. But I'm very much a beginner in php scripting. Here is the script on the page <?php ...
2
by: Corne' Cornelius | last post by:
Hi, When you open a file for writing/appending with open() or fopen(), and you have multiple applications that might want to write to the same file at the same time, could that cause weirdness...
10
by: Grocery Clerk | last post by:
I know open() returns a file descriptor and fopen() returns a pointer to FILE. The question is, when do I use fopen() and when do I use open()? Could someone give me an example when to use one...
6
by: Rolf Schroedter | last post by:
(Sorry for cross-posting). I need to access large files > 2GByte (Linux, WinXP/NTFS) using the standard C-library calls. Till today I thought I know how to do it, namely for Win32: Use open(),...
13
by: Blue | last post by:
Hi , Can any one please let me explain me the diffrences between "open"/ "fopen" or "read"/"fread" or "write/fwrite". I know that "open" /"read" / "write" are system calls and "fopen"...
4
by: Frank | last post by:
Could someone tell me how to open a file at run time that I didn't know the name of at compile time? I know how to open a file at compile time when I know what the name is going to be. FILE...
9
by: ferbar | last post by:
Hi all, I'm trying to read from the txt file 'ip.packets.2.txt' using the read function. It seems everything ok, but I get a -1 when executing >>bytesr = read(fdo1, bufread, 2); The 'open'...
8
by: someone | last post by:
I'm making an program that encodes text, and then writes it into another text file. The problem is that I can't seem to get the "file exists" checking right. If I use the command (coder is the...
4
by: Claire DURAND | last post by:
Hi, I try to open a distant (not local) XML file in PHP to read an RSS feed. I can open an HTML page and read it with the file() function. But as soon as I try with a RSS feed instead of...
3
by: siyaverma | last post by:
i am trying to upload csv file from user's computer to main server the code i am using is if(((isset($_GET)) && ($_GET=="yes")) ) { $typefield = $_GET; echo...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.