user2801966
user2801966

Reputation: 468

Connection time out while reading contents from a server

Hi Here's what i am trying to do .

$contents = file_get_contents('http://123.34.56.123:3000/?location=Example'); //Not the original ip 
//Node script running on port 3000 

Everything is working fine on localhost and when i access this url directly from browser but on my web server i ma getting this error

file_get_contents(http://123.34.56.123:3000/?location=Example) Failed to open stream: Connection timed out in ....

And i have tried connecting with curl , sockets and file stream but everything getting the connection is timing out though it's working fine on my local server

I have also used ini_set('max_execution_time', 300); but it didn't help anything

Note : file_get_contents('http://www.google.com'); Works fine on the web server

Anyone can help me understand why i am getting this error ? i have tried almost everything i could to fix this issue.

Upvotes: 0

Views: 491

Answers (2)

user4133895
user4133895

Reputation:

First of all you need to check that whether the content which you are fetching from resource is encoded or not, means if the content is encoded with JSON then you need to use json script to decode it and after that you will be able to be get the content..

also check the resource URL and the port of the server that you are using. If your port 3000 is blocked then it also not works fine.

I though it will help you.

Upvotes: 1

user2801966
user2801966

Reputation: 468

Seems like the server i was using was blocking connection on port 3000 , and it makes complete sense as normally web host use 80 and 443 port only to make i/o connection . I contacted with my web host they unlocked the 3000 port and it's working perfectly now .

Upvotes: 0

Related Questions