473,246 Members | 1,366 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,246 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 15500
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...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

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.