im trying to to store data to ipfs via php , i use curl to communicate with api , it works find on my local node , but i want to use external node from infura.io

but for some reason ipfs.infura.io is refusing my connection via php even a simple command like ... i've tried it on my localhost as well as couple of servers

here is a simple endpoint which you can open in the browser and get the output


but when i try to open it via php i get

Failed to connect to ipfs.infura. io port 5001: Connection refused

or when using another method like file_get_contents

file_get_contents(ipfs.infura.io:5001/api/v0/pin/add?arg=QmeGAVddnBSnKc1DLE7DLV9uuTqo5F7QbaveTjr45JUdQn): failed to open stream: Connection refused

i've tried it on local host and multiple server , i get the same result even via ssh command line enter image description here

enter image description here

any idea why is this happening ?

here is a simplified version n of my code

    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL,"https://ipfs.infura.io:5001/api/v0/pin/add?arg=QmeGAVddnBSnKc1DLE7DLV9uuTqo5F7QbaveTjr45JUdQn");
    curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($curl, CURLOPT_FAILONERROR, true);
    $res = curl_exec($curl);
    if (curl_errno($curl)) {
        $error_msg = curl_error($curl);
        echo ('error ...');
        echo ($error_msg);


1 Answer 1


Your code works fine for me. I also can get correct response with curl. I think you should search the reason of your problem in your network infrastructure. Here is https://stackoverflow.com/a/2333446/7581809 good discussion why this problem can happen. You said you tryed different servers. Are these servers in same network ? May be there is a firewall in this network, which rejects your packets to infura. Try another server from another network.

  • yep still not sure what the problem is , but trying it on different server worked
    – max
    Commented Feb 1, 2022 at 17:49
  • This seems to be a simple networking problem, probably port 5001 is blocked as an external port in your local firewall/proxy/remote firewall/router. This is common if you use a network inside a company. If curl works somewhere else, it means it is a networking issue. Commented Feb 2, 2022 at 15:16
  • @GiuseppeBertone if we send request to endpoint on port 5001 .... we still use our 80 port to send the request aren't we ?
    – max
    Commented Feb 6, 2022 at 17:12
  • @max No, we are not. When you open TCP connection one of ephemeral ports is used on client side for outgoing connection. If you have 80 port used by some process (your http server for example) nothing else can use this port. en.wikipedia.org/wiki/Ephemeral_port Commented Feb 6, 2022 at 17:29

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.