fopen() - http Wrapper Issue
Moderator: General Moderators
fopen() - http Wrapper Issue
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.
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.
- AbraCadaver
- DevNet Master
- Posts: 2572
- Joined: Mon Feb 24, 2003 10:12 am
- Location: The Republic of Texas
- Contact:
Re: fopen() - http Wrapper Issue
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.
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Re: fopen() - http Wrapper Issue
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.AbraCadaver wrote:php.ini: allow_url_fopen = On
- AbraCadaver
- DevNet Master
- Posts: 2572
- Joined: Mon Feb 24, 2003 10:12 am
- Location: The Republic of Texas
- Contact:
Re: fopen() - http Wrapper Issue
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.John Cartwright wrote: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.AbraCadaver wrote: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.
Re: fopen() - http Wrapper Issue
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.
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.
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Re: fopen() - http Wrapper Issue
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.
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Re: fopen() - http Wrapper Issue
Did you restart Apache / whatever server your using after making the php.ini changes?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.
Re: fopen() - http Wrapper Issue
Yes. I restarted the web server. Several times. Should the entry be in a specific location in the php.ini file?
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Re: fopen() - http Wrapper Issue
It should be in whichever php.ini was loaded by the PHP engine (there may be several different ones on your file system).ghsws wrote:Yes. I restarted the web server. Several times. Should the entry be in a specific location in the php.ini file?
Take a peak at phpinfo(); function and which will have a loaded configuration file path in there.
Re: fopen() - http Wrapper Issue
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.
Any other ideas?
Thanks.
- AbraCadaver
- DevNet Master
- Posts: 2572
- Joined: Mon Feb 24, 2003 10:12 am
- Location: The Republic of Texas
- Contact:
Re: fopen() - http Wrapper Issue
I've never seen it, but it appears that the http wrapper is not installed. It should be built-in.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.
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.
Re: fopen() - http Wrapper Issue
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.
I had to uncomment the "extension=curl.so" line in my php.ini file and restart my web server. Problem solved.