PHP file_get_contents sometimes failed to open stream Http request failed - php

I have an ajax call that gets many, many pages of contents from a website, but it fails to open steams sometimes even though the same exact links that failed to open streams works just fine, when I ran them again. The problem is, then other links would failed to open stream. Anyone know why this is happening?
Warning: file_get_contents(http://www.merriam-webster.com/browse/dictionary/a/acoustically.htm): failed to open stream: HTTP request failed!

Related

Image not loading, Failed to open stream: HTTP request failed

I have the following problem on a Magento2 Fresh installation with dummy data, using the theme [Revo]: https://themeforest.net/item/revo-responsive-magento-2-shopping-theme/18339484
Error filtering template: Warning:
getimagesize(https://website.com/media/wysiwyg/imageslider/slider-1.jpg):
failed to open stream: HTTP request failed! HTTP/1.1 401 Unauthorized
in
/var/www/html/nobacco/vendor/magento/framework/Image/Adapter/AbstractAdapter.php
on line 304
Permissions are correct, nginx settings seem good the image exists on the server and is accessible through the same url and the user rights seems alright too.. Any ideas?
Before this error I was getting an error on vendor/(cant remember the full path)/Image.php

how to solve : failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request

i am using yahoo finance API where i call an API and that gives me a CSV file. below are my codes.
$handle = fopen('http://download.finance.yahoo.com/d/quotes.csv?s=INFY&f=l1c1va2xj1b4j4dyekjm3m4rr5p5p6s7n=.csv', "r");
while execute this line it throws an warning that is
failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request
i have spend more time on google but no result yet.
but sometimes its working fine without throwing any warning.
another things it also working fine in local. there is no working throw while execute
if anyone knows the exact solution please help me.
Thanks
Sanjib

What are the factor to get this ERROR `failed to open stream: HTTP request failed! `?

Hi I would like to ask why i get this ERROR
I am using file_get_contents()
and I am currently receiving an ERROR
failed to open stream: HTTP request failed!
I would like to know how to prevent this.
I also search about curl and it is better than what I'm using right now its not matter for me if I re code or not. What i want to know is the factors why I am receiving this ERROR.
I have done searching but still i don't have clear view with this. Any comments and knowledge is well appreciated.Thanks!

Identifying root cause of a timeout in PHP

A little while ago I noticed some Soap errors emitting from my app and I started to investigate them. Stuff like:
SoapClient::SoapClient(http://###.###.###.###:8080/path/to/some.wsdl): failed to open stream: HTTP request failed!
SoapClient::SoapClient(): I/O warning : failed to load external entity "http://###.###.###.###:8080/path/to/some.wsdl"
SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://###.###.###.###:8080/path/to/some.wsdl' : failed to load external entity "http://###.###.###.###:8080/path/to/some.wsdl"
It looked like a timeout on the remote server (WSDL caching was turned off). After bouncing that server and having no luck, I tried to just file_get-contents() the WSDL to see what would happen...
No dice: After about 20 seconds or so I got the same stream error:
file_get_contents(http://###.###.###.###:8080/path/to/some.wsdl) [<a href='function.file-get-contents'>function.file-get-contents</a>]: failed to open stream: HTTP request failed!
In a last ditch effort, I tried to read the contents via the curl_* functions, and I do in fact get what I'm looking for.
... tl;dr?
SoapClient and file_get_contents appear to be timing out (though not an explicit "Failed to open stream, connection timed out")
It appears to be related to streams since curl gives me what I'm looking for.
I've got a lot of code that depends on SoapClient and file_get_contents so switching to an all curl solution isn't really an option.
This is not a DNS issue as I can resolve external names fine (and my target resource is an IP)
allow_url_fopen is enabled.
Any ideas?
allow_url_fopen needs to be On in your PHP settings for file_get_contents to work with URLs. It'll give you that exact error otherwise. Double-check your PHP settings by loading a page with a phpinfo(); call to make sure they're not being overridden by a different php.ini or .htaccess file.
I'd guess a firewall problem otherwise but you say curl works from inside PHP, which would be opening sockets in the same manner.

I'm having trouble getting file_get_contents() to work on my server

I've got a php file on my server that looks like this:
echo file_get_contents('http://server.com/some.file');
and I get the following error:
Warning: file_get_contents(http://server.com/some.file) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found in /path/to/php/file on line 6
What's got me confused is that if I link to the/full/server/path instead of http:// it seems to load fine. Also, I can get it to load content from other domains using http://, just not my own.
Any ideas?
As deceze sayd test the path in a browser. It should work the same as in PHP. If the path you write is correct check your URL rewrites (maybe you have them different for the server IP).

Categories