Page 1 of 1

fopen() - http Wrapper Issue

Posted: Tue Feb 01, 2011 11:53 am
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.

Re: fopen() - http Wrapper Issue

Posted: Tue Feb 01, 2011 12:04 pm
by AbraCadaver
php.ini: allow_url_fopen = On

Re: fopen() - http Wrapper Issue

Posted: Tue Feb 01, 2011 12:15 pm
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.

Re: fopen() - http Wrapper Issue

Posted: Tue Feb 01, 2011 12:30 pm
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.

Re: fopen() - http Wrapper Issue

Posted: Tue Feb 01, 2011 12:52 pm
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.

Re: fopen() - http Wrapper Issue

Posted: Tue Feb 01, 2011 12:54 pm
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.

Re: fopen() - http Wrapper Issue

Posted: Tue Feb 01, 2011 12:54 pm
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?

Re: fopen() - http Wrapper Issue

Posted: Tue Feb 01, 2011 12:58 pm
by ghsws
Yes. I restarted the web server. Several times. Should the entry be in a specific location in the php.ini file?

Re: fopen() - http Wrapper Issue

Posted: Tue Feb 01, 2011 1:01 pm
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.

Re: fopen() - http Wrapper Issue

Posted: Tue Feb 01, 2011 2:11 pm
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.

Re: fopen() - http Wrapper Issue

Posted: Tue Feb 01, 2011 2:15 pm
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.

Re: fopen() - http Wrapper Issue

Posted: Wed Feb 02, 2011 8:14 am
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.