Everything is working fine on localhost but first I host the website after up and downs and overcoming over I got stuck at this problem:
file_get_contents(http://....): failed to open stream: Connection timed out
I have not used file_get_function anywhere in my code but it is giving the error. Where is this coming from?
What does Connection time out mean? I checked on SOF but I get more and more confused. Any help will be appreciated!
Can anyone give a detailed explanation or link?
There could be two main reasons for this:
Your server cannot resolve the domain name (try nslookup from shell) - if this is the problem, you can try to set Google nameservers (8.8.8.8, 8.8.4.4)
There are firewall restrictions, which do not allowed to make inbound/outbound connection from your server
You can try out a cURL connection instead, maybe this helps.
file_get_contents() does not deal with slow network connections or redirects for getting remote files. You can use fsockopen() which allow a custom connection timeout value
try to use cURL
See this TIP in the php manual
A URL can be used as a filename with this function if the fopen
wrappers have been enabled. See fopen() for more details on how to
specify the filename. See the Supported Protocols and Wrappers for
links to information about what abilities the various wrappers have,
notes on their usage, and information on any predefined variables they
may provide.
If your live site does not have allow_url_fopen = On then this function will not allow you to use url's
Related
I know there is some similar topic, but not the same. I have a working code, tested with a lot of different url - http and https as well - without any problem. Then, I found a website ... when I asking the URL header, I got empty array answer.
get_headers("https://www.diversalertnetwork.org/diving-incidents/Divers-air-consumption-appeared-unbelievably-good", 1);
And the result is an EMPTY array.
Array
(
)
I am also try with CURL but same result. I try to download the url's content but nothing. You can try it. Surprise! If I modify to http:// from https://, it will start working. Of course, the https link working very well in a browser. Also, the get_headers working with other https:// links.
With curl I using my own browser's useragent, so that is a real if the server try to detect for any security reason. I really do not know what can I do, and most important, what happening, why there is no any answer, not an error or whatever.
php 5.6
My browser shows warning about that site's HTTPS connection:
The connection to this site uses an obsolete protocol (TLS 1.0), an obsolete key exchange (RSA), and an obsolete cipher (3DES_EDE_CBC with HMAC-SHA1).
So it might simply be that on your system making HTTPS connections with sites that only support outdated security protocols is disabled.
Which Apache config settings regarding SSL are relevant, can be found here: https://superuser.com/a/882651
For the past four hours I have been trying to configure TCAdmin to work with whmcs. I set up the server in the server setting of WHMCS and added all the configurable options. I got my first demo order and when I select "Accept Order" I get this error:
Order Accept Encountered Problems
Curl error: couldn't connect to host Url: http://xx.xx.xxx.xxx:8880/billingapi.aspx
For some reason WHMCS can't connect, but when I connect I get this: "Visit http://help.tcadmin.com for help". I tried that. Still no luck.
So I went into my server, found the billingapi.aspx file and it said this:
This is a marker file generated by the precompilation tool, and should not be deleted!"
Does anyone have any suggestions or solutions? All help is appreciated :)
-Max
Curl is failing to connect but you think it should be able to? There are a few things to check:
Is the address being passed to Curl really right? (It's so easy to get this wrong!)
Is the target host reachable from the host making the request (the origin)? Firewall rules can cause all sorts of strange problems here. Check if you can do a read-only request from the origin and get through that way.
Is the target port on the target host accessible from the origin? Again, it's the firewall, and port 8880 is not one that I'd expect to normally be a permitted outgoing target in an aggressive firewall regime; a specific rule may well be needed.
Is there a problem with DNS? Hopefully not, but if name resolution itself keeps failing then that might be a significant issue. (This won't be the case if you use an IP address instead of a DNS host name, but that can cause the request to fail in other ways — such as if the target hosts many sites — so don't jump to conclusions here.)
Other problems that are theoretically possible (e.g., bad request contents, wrong path in the URL) would give different error messages.
I am trying to simply use file_get_contents() to get content of http://www.google.com/search?hl=en&tbm=nws&authuser=0&q=Pakistan with same code on 2 different servers. One is getting every thing file while other is getting 403 error. I am unable to know what exactly the reason is. I used phpinfo() on both servers.
One difference I observe is that one use apache2 while other use some other HTTP server named LiteSpeed V6.6. But i don't know how if it affect this file_get_contents() method. For more detail you can see their phpinfo() page link below.
Where file_get_contents getting 403 the phpinfo is; http://zavahost.com/newsreader/phpinfo.php
while where it is working file , here is the phpinfo: http://162.243.5.14/info.php
I will be thankful if someone can tell that what is effecting file_get_contents()? Please let me know if any idea?
403 is an Unauthorized Error. That means you lack sufficient permission to connect to the content at that server. I'm not sure if this could be due to the inability to fetch data from your hosting provider, but it could also be denied based on header information the remote server has flagged as unauthorized.
Try using the answer on this post: php curl: how can i emulate a get request exactly like a web browser? to curl the same data from the server that is getting the 403
I tried to sent an SMS using an API with file_get_contents() in PHP.
Eg.
file_get_contents("http://testsmssite/SMS.php?username=xx&password=ccc&message=MESSAGE&numbers=1111111111&sender=11111");
In local machine it works well.
If i Put it in to server[SERVER A] its not working.If i change the code
ie.
file_get_contents("http://google.com"); it works fine in both server and local.
if i put this page ie
file_get_contents("http://testsmssite/SMS.php?username=xx&password=ccc&message=MESSAGE&numbers=1111111111&sender=11111");
in to another server[SERVER B] it works fine.
If it is any problem with my [SERVER A] then how it open google?
Can any one help me to fix this issue ?
Instead of using file_get_contents, try using curl. See what you get back as a response and check curl_error. There are many possible reasons that could cause the request to fail.
Check your error log. If file_get_contents fails, it tells you the reason why in the PHP error log if you log warnings and notices.
In a related question, Why doesn't file_get_contents work?, some have created a collaborative wiki answer that deals with how to trouble-shoot file_get_contents in detail. Maybe the infos and comments help you as well.
Can you check if allow_url_fopen is true/enabled, for more http://www.php.net/manual/en/filesystem.configuration.php#ini.allow-url-fopen? It could be a reason. And yes, Curl could be a better option.
Check if http://testsmssite is accessible from Server A (try pinging it). Maybe you'll have to add it to /etc/hosts. Or maybe you have to change settings on testsmssite. IMO it's network issue, not related to PHP itself (since on server A PHP is able to load data from http://google.com)
I am currently using an image manipulation script to do some work on uploaded images and I'm running into a problem in my dev environment. This same code works on my production server.
The error is:
PHP Warning: imagecreatefromjpeg(): php_network_getaddresses:
getaddrinfo failed: Name or service not known in /path/to/script.php
on line 75
The line of code on 75 is:
$this->img = imagecreatefromjpeg(PHPTHUMB."?src=/".$this->image_path);
which creates an image that is loaded from another made by phpThumb, which is used for further manipulation.
Any ideas on how to solve this? Can anyone shed some light on what the error means?
Thank you,
Edit:
Just as a further bit of insight, if i visit PHPTHUMB . "?src=/" . $this->image_path in my browser, the image loads fine
User agent in php.ini did not solve the problem as indicated here
EDIT (SOLUTION): I had to add the INTERNAL 192.168.204.XXX IP into the hosts file, so that http://dev.mysite.com resolved correctly. Trying both 127.0.0.1 and the external IP yielded no result, but the internal works perfectly. Thanks for everyone's efforts,
I'm totally not sure about the cause of that error, but this is my best guess.
There is a particular PHP Setting which enables you to treat URLs as files. Normally imagecreatefromjpeg accepts a filename, I think. Since you are passing a URL, you need to make sure the particular setting is enabled. I believe you can find more info about it here: http://us2.php.net/file
filename
Path to the file.
Tip
A URL can be used as a filename with this function if the fopen
wrappers have been enabled. See
fopen() for more details on how to
specify the filename and List of
Supported Protocols/Wrappers for a
list of supported URL protocols.
Fopen wrappers: http://us2.php.net/manual/en/filesystem.configuration.php#ini.allow-url-fopen
Your dev environment may not be setup with this, but your production environment could be.
Edit
This page lists your error:
http://bugs.php.net/bug.php?id=11058
and mentions that a possible fix is by modifying your hosts file to explicitly include the ip/dns of the server you're accessing.
i tryed to reconfigure my named
configuration, without any result, to
fix this. the problem was solved by
adding the following line to my
/etc/hosts:
194.97.55.147 mx.freenet.de
Maybe you can try this?
did you also check that allow_url_fopen is set to On in php.ini?
I saw that they did mention that in the article you referred to in your post.
EDIT: Also, what OS and what PHP version are you running?
Just read this on php.net: "On Windows versions prior to PHP 4.3.0, the following functions do not support remote file accessing: include(), include_once(), require(), require_once() and the imagecreatefromXXX functions in the GD Functions extension."
EDIT2:
I just read what was written in the comments, your allow_url_fopen is set to On, sorry about that.
But OS, PHP version and phpinfo() would help in finding the problem.
The error message suggests something is wrong at a networking level. Thus, if possible, bypass that. Try using the path to the thumbnail generator, instead of a network address.
If that's not an option, try something that will give you more granular error messages. I suggest CURL. At the very least, it should yield a more informative error message.
The simple fact that this is failing is because on your webserver, your DNS resolution is broken.
If you have SSH access to your server, try the following command
dig hostname
where hostname is the host name from PHPTHUMB
This will probably fail.
Assuming that you're using Linux, my suggestion would be to edit your /etc/resolv.conf (as root)
and add the following line before any other lines beginning with "nameserver"
nameserver 4.2.2.2
This should hopefully fix things, though you may have to restart apache (or whatever webserver you're using)!
The issue here is that php fails to resolve the url that you provide as PHPTHUMB as stated in this bug report on php.net. This possibly means that it's the fault of the operating system/web server, in which case you can enter the ip address of the server you are connecting to into your hosts file manually.