Viewed   180 times

Here is a snippet of my code

$fp = fsockopen($s['url'], 80, $errno, $errstr, 5);
        fwrite($fp, $out);

When I run it, it outputs:

unable to connect to (php_network_getaddresses: getaddrinfo failed: Name or service not known

I'm using this to submit GET data to the $s['url']

I can't figure out why. Any help would be greatly appreciated.



If you only want to submit GET data to the URL, you should use something straightforward like file_get_contents();

$myGetData = "?var1=val1&var2=val2";
Thursday, November 10, 2022

This is the equivalent using cURL,

    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_URL, "http://" . $host . $request); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Connection: close'));
    curl_setopt($ch, CURLOPT_TIMEOUT, 2); 
    $response = curl_exec($ch); 

BTW, it's not safe to make query string like that. You should use http_build_query() to build it so it's properly encoded.

Saturday, September 3, 2022


Your DSN format is wrong, it shouldn't have those quotes in there. This is the right format

 //$con=new PDO($dsn, $user, $password);
 $con=new PDO('mysql:dbname=testdb;host=','root',''); 

See Manual

Thursday, August 25, 2022

From a little ways down the fsockopen() page (have to scroll almost to the bottom):

UDP sockets will sometimes appear to have opened without an error, even if the remote host is unreachable. The error will only become apparent when you read or write data to/from the socket. The reason for this is because UDP is a "connectionless" protocol, which means that the operating system does not try to establish a link for the socket until it actually needs to send or receive data.

I'm going to guess that's your problem, I guess you have to do a test read/write to see if it was really successful or not.

Sunday, December 18, 2022

Thanks Prerak,

This is the answer, my database is on the same machine so I just needed to edit:

$servername = "localhost"

Now everything is working just fine.

Wednesday, August 3, 2022
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :