Curl Error Hostname Not Found in DNS Cache - php

I have a website (www.example.com | 123.456.789), in that machine i only have 1 web app running. i am trying to use php file_get_content() to a file which in my own server (located on some file like /var/www/my_site/public_html).
The PHP code i am referring is:
$url = 'http://example.com/282-home_default/short-wallet-tan.jpg';
var_dump($url);
$json = #file_get_contents($url);
var_dump($json);
die();
However it always returns error. When i try to do it manually, using CURL
I can confirm that i can CURL other website such as ~$ curl google.com
Can anyone suggest me what to do to resolve this. Thanks
I am using Ubuntu 14.04 LTS to host my webapp.
Some of the solution regarding this question, points out that i should downgrade my version of curl. Did that but still have the same problem.

curl failed to connect to that host's TCP port number 80. You're either not running the http server on port 80, you've made curl try to connect to the wrong server or there's something else in your network that prevents the connect handshake to succeed.

Related

curl https://SERVER_IP:8443 works on Mac but not when I SSH into server

Via terminal on a Mac (PHP 7.1.23), I can issue a curl (curl 7.54.0) command via the CLI such as:
curl https://www.SERVER_HOSTNAME:8443
and it works without error.
I SSH into the VPS Linux server running x86_64-redhat-linux-gnu with curl 7.61.1 and PHP 7.3.5 and if I do a curl command without the port:
curl https://www.SERVER_HOSTNAME
it works fine but as soon as I add the port it chokes.
curl https://www.SERVER_HOSTNAME:8443
gives this error:
"SSL certificate problem: unable to get local issuer certificate
More details here: https://curl.haxx.se/docs/sslcerts.html
curl failed to verify the legitimacy of the server and therefore could not establish a secure connection to it. To learn more about this situation and how to fix it, please visit the web page mentioned above.
The actual certificate is not self signed. It is via Godaddy with a Bundle and a good CA.
Any suggestions on what I need to fix or set?
Thanks in advance.

CURL won't work over CURLOPT_PROXY server issue?

I am trying to use Luminati.oi proxy service to crawl URLs but there seems to be a problem with my server connecting to the proxy and utilizing the CURLOPT_PROXY functionality.
$curl = curl_init('http://lumtest.com/myip.json');
curl_setopt($curl, CURLOPT_PROXY, 'http://example:24000');
curl_exec($curl);
$result = curl_exec($curl); echo $result;
echo 'Curl error: ' . curl_error($curl);
curl_close($curl);
I get no response at all from the target URL and the curl_error() function returns Curl error: Failed to connect to exmaple port 24000: Connection refused there are several variations on how to compose the CURL that Luminati.io provides, none seem to work.
If I remove the CURLOPT_PROXY option and just send the request direct from my server with no proxy, it works just fine and I get the correct response back from the target URL. So my server seems okay with CURL just not the proxy function.
The URL and port for the proxy server at luminati.io seem to work fine when using the desktop proxy manager. So the proxy service seems to work okay, the target URL is good and my server can use CURL with no problem, so it seems the issue is isolated around the CURLOPT_PROXY not working. The good people over at Luminati.io think there is some type of server setting or firewall in my Apache Linux server that wont allow the proxy connection to occur, I can't find this setting anywhere and Hostgator seems useless and apathetic when asked.
So I'm hoping someone can provide some greater insight into why CURLOPT_PROXY function wont work.
You can ask Hostgator to give you access to port 22225. I think this is the correct port used by Luminati.
This is how you can contact Hostgator: http://support.hostgator.com/articles/open-new-ports

Best way to check if your VM is running

Browser
VM ip = 172.16.67.137
I goto : http://172.16.67.137:1234/vse/accounts.count on my local brower
I got this response
Object
data:Object
account_count:20
message:"Success"
status:200
Terminal
But how comes when I tried ping that URL
ping http://172.16.67.137:1234
ping http://172.16.67.137
All of them return me
ping: cannot resolve http://172.16.67.137:1234/vse/accounts.count: Unknown host
Did I do something wrong or missing any steps ?
I just want to check if my VMs is running before do any other action, otherwise, throw some errors.
Hope someone can shed some lights on this ...
Ping only works with url's not uri's or ports.
When I say URL I mean with out http://
You would have to do this:
ping 172.16.67.137
Ping does not work with ports
You could use telnet to check it.
telnet 127.0.0.1 8080
From the terminal run curl to get the response
curl http://172.16.67.137:1234/vse/accounts.count

No response to HTTP requests sent via cURL to certain hosts

cURL (via PHP) on my local machine is working fine, but on a production server, I am getting no response when connecting to some hosts, while others are working Fine. Further, I can use wget to download from the hosts curl cannot.
The problem appears to be - my server is on IPv6, and it cURL is trying to make connections via IPv6, to hosts who do not support it. The solution for PHP is:
CURLOPT_IPRESOLVE = CURL_IPRESOLVE_V4
command line:
curl -4 http://host-that-does-not-have-an-ipv6-address
Also if you are using a SOCKS proxy, in PHP, the following may help:
CURLOPT_PROXYTYPE = 7

Apache / PHP Unable to communicate with Tomcat JavaBridge

My project uses PHP JavaBridge, I have installed WAMP, JRE 6.0, and Tomcat 6.0.32
I can now access http://localhost:8080/ successfully but when I run my PHP site it gives me the following error
warning: fsockopen() [function.fsockopen]: unable to connect to localhost:8080 (A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. )
Can anyone please help me with this issue?
EDIT
Forgot to mention that I am using Windows 7
My comment above worked as a solution and hence this answer, so that in future others get it.
Can you 127.0.0.1:8080 instead of localhost:8080? See what do you get?
fsocketopen takes the hostname and it should be a valid domain, in your case, (in general) it could be a valid domain as long as you have an entry for localhost in your hosts file (C:\Windows\System 32\drivers\etc\hosts). See if you have something similar to that.

Categories