3

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

Curl Command

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.

2
  • Is your website a secret?Because I want to test that bit of code Commented Oct 20, 2015 at 5:34
  • not really, fyi i can curl the file from another server (e.g from onlinecurl.com) Commented Oct 20, 2015 at 5:38

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

4 Comments

When i try to do the same curl using onlinecurl.com, it works perfectly. The http server is running on port 80, i can confirm this.
then you have something on your machine/network that prevents it from working
My machine is a VM which has its own internal IP (NAT) and its own public IP. It is similar with AWS EC2, where each instance has an private IP and a public IP (Elastic IP). Does this give you any hint ? I've allowed all TCP and UDP for port 80
I had the same issue with a perfectly working url to which I had the same output form curl. It was only happening on my vagrant development machine, which i restarted to resolve the issue. It would however be nice to know what the issue was and how to resolve this just in case this happens again or on my production sever.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.