fopen() - http Wrapper Issue

Need help installing PHP, configuring a script, or configuring a server? Then come on in and post your questions! We'll try to help the best we can!

Moderator: General Moderators

Post Reply
ghsws
Forum Newbie
Posts: 5
Joined: Tue Feb 01, 2011 11:41 am

fopen() - http Wrapper Issue

Post by ghsws »

I have a problem that I believe may be related to fopen() and the availability of the http protocol handler (wrapper). The fopen() function - fopen(http://www.mydomain.com/phptest/index.php) fails. The message is similar to "failed to open stream: No such file or directory in /mypath/phptest/index.php". It appears as though fopen() is attempting to open the file locally. My research indicates the following about fopen(): "If no wrappers for that protocol are registered, PHP will emit a notice to help you track potential problems in your script and then continue as though filename specifies a regular file."

I listed the available wrapper using: print_r(stream_get_wrappers());
The following array was returned: Array ( [0] => php [1] => file [2] => data [3] => compress.zlib )

It appears as though the http wrapper is not available and php is therefor attempting to open the file locally.

Can someone confirm my findings and provide direction for resolving? Ho does one "enable" the http wrapper?

Thank you in advance for your help.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: fopen() - http Wrapper Issue

Post by AbraCadaver »

php.ini: allow_url_fopen = On
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: fopen() - http Wrapper Issue

Post by John Cartwright »

AbraCadaver wrote:php.ini: allow_url_fopen = On
allow_url_fopen can open you up to potential security risks, i.e., code injection. A better alternative would be to use file_get_contents() or the cURL libary that do not rely on allow_url_fopen configuration.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: fopen() - http Wrapper Issue

Post by AbraCadaver »

John Cartwright wrote:
AbraCadaver wrote:php.ini: allow_url_fopen = On
allow_url_fopen can open you up to potential security risks, i.e., code injection. A better alternative would be to use file_get_contents() or the cURL libary that do not rely on allow_url_fopen configuration.
It's not the function it's the "wrapper" that is restricted by allow_url_fopen. The fopen term in the setting name may be misleading. file_get_contents() won't work with http either because the URL (http/https/ftp/ftps/etc.) wrappers are restricted.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
ghsws
Forum Newbie
Posts: 5
Joined: Tue Feb 01, 2011 11:41 am

Re: fopen() - http Wrapper Issue

Post by ghsws »

Thanks for the replies so far.

I should have added that phpinfo showed "allow_url_fopen = On" prior to my posts. I added it to the php.ini file, as suggested, however I get the same results.

I am attempting to get a third-party php application working, so I have no choice regarding the use of fopen().

The results of print_r(stream_get_wrappers()) is still Array ( [0] => php [1] => file [2] => data [3] => compress.zlib ) leading me to believe that the http wrapper is still not available.

Any other ideas?

Thanks.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: fopen() - http Wrapper Issue

Post by John Cartwright »

Your right. I use cURL for pretty much everything regarding a remote url. The possibility of code injection is something that doesn't sit well with me.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: fopen() - http Wrapper Issue

Post by John Cartwright »

ghsws wrote:I should have added that phpinfo showed "allow_url_fopen = On" prior to my posts. I added it to the php.ini file, as suggested, however I get the same results.
Did you restart Apache / whatever server your using after making the php.ini changes?
ghsws
Forum Newbie
Posts: 5
Joined: Tue Feb 01, 2011 11:41 am

Re: fopen() - http Wrapper Issue

Post by ghsws »

Yes. I restarted the web server. Several times. Should the entry be in a specific location in the php.ini file?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: fopen() - http Wrapper Issue

Post by John Cartwright »

ghsws wrote:Yes. I restarted the web server. Several times. Should the entry be in a specific location in the php.ini file?
It should be in whichever php.ini was loaded by the PHP engine (there may be several different ones on your file system).

Take a peak at phpinfo(); function and which will have a loaded configuration file path in there.
ghsws
Forum Newbie
Posts: 5
Joined: Tue Feb 01, 2011 11:41 am

Re: fopen() - http Wrapper Issue

Post by ghsws »

I checked and confirmed that there is only one php.ini file in the filesystem and it is the one reported by phpinfo.

Any other ideas?

Thanks.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: fopen() - http Wrapper Issue

Post by AbraCadaver »

ghsws wrote:I checked and confirmed that there is only one php.ini file in the filesystem and it is the one reported by phpinfo.

Any other ideas?

Thanks.
I've never seen it, but it appears that the http wrapper is not installed. It should be built-in.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
ghsws
Forum Newbie
Posts: 5
Joined: Tue Feb 01, 2011 11:41 am

Re: fopen() - http Wrapper Issue

Post by ghsws »

Thank you all for your help. I have found the problem.

I had to uncomment the "extension=curl.so" line in my php.ini file and restart my web server. Problem solved.
Post Reply