Failed to connect to port 8080: Connection refused Error number: 7 (cURL)

10,454

Since the problem occurs when you changed the server, I would suspect that the problem is the outgoing server blocking the port.

This, admittedly old, forum post says:

I don't know if it applies to anything other than shared hosting, but Godaddy shared hosting has all outgoing ports other than 80 blocked by their firewall

and

The problem is that Godaddy shared hosting will not let you make requests from your site that go to any port other than 80.

It's like having a house where all of the doors and windows, except the front door, are welded shut.

and

Talked to Godaddy Support and was told port 8080 is blocked, even on their dedicated servers.

This might have changed in the meantime, but since you are experiencing the problem I don't think it has.


Possible solutions:

  • Don't use awful hosting (Godaddy has a terrible reputation)
  • Somehow persuade Godaddy to open up the port
  • Find a proxy that lets you use port 80 to get the request outside of Godaddy's network
Share:
10,454
Khairul Alam
Author by

Khairul Alam

I'm a Full-Stack Web Developer (LAMP). But I'm still learning things. I know there's a long way to go. I have a Masters in Computer Science & Engineering.

Updated on June 04, 2022

Comments

  • Khairul Alam
    Khairul Alam about 2 years

    I have the following code -

    $url = 'http://52.77.156.123:8080/LebuPay/check-payment';
    
    $ch = curl_init($url);
    
    $data = array(
    "successURL"  =>  'http://jsonviewer.stack.hu',
    "failureURL"  =>   'http://jsonviewer.stack.hu',
    "amount"  => $amount,
    "orderTransactionID"  => $order_id,
    "firstName" =>   "",
    "lastName"  =>  "",
    "email" => "",
    "mobileNumber"  => "",
    "accessKey" =>  "some_random_key"
    );
    
    $jsonEncode = json_encode($data);
    
    curl_setopt($ch, CURLOPT_POST, TRUE);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonEncode);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE );
    curl_setopt($ch, CURLOPT_HEADER, TRUE);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
    
    $result = curl_exec($ch);
    $result = json_decode($result, true);
    
    echo "Error CURL: " . curl_error($ch) . " \nError number: " . 
    curl_errno($ch);
    
    curl_close($ch);
    
    
    $token = $result['token'];
    header("location: http://52.77.156.123:8080/LebuPay/execute-payment?token=$token");
    

    The code works on my localhost but when I upload it on the server (Godaddy linux). It gives me error "Failed to connect to 52.77.156.123 port 8080: Connection refused Error number: 7"

    The API I'm trying to get response from is hosted on AWS.

    Any idea how I can solve this problem? Thanks.