PHP Socket连接到API

I'm trying to connect to an API using PHP Sockets.

I've tried it in many ways, but I can't get it working. I know there is other answers, but no one works. I really can't achieve it. I'm trying it at least two days.

Here is the error:

php_network_getaddresses: getaddrinfo failed: Name or service not known

Code (Sockets - It does not work):

var $url = 'api.site.com.br/';

public function getUsers(){

    $path = "users/?accesstoken=c24f506fe265488435858925096bc4ad7ba0";
    $packet= "GET {$path} HTTP/1.1
";
    $packet .= "Host: {$url}
";
    $packet .= "Connection: close
";

    if (!($socket = fsockopen($this->url,80,$err_no,$err_str))){
      die( "
 Connection Failed. $err_no - $err_str 
");
    }

    fwrite($socket, $packet);
    return stream_get_contents($socket);
}

Code (Curl - It Works!):

public function getUsers2(){
    $path = "users/?accesstoken=c24f506fe265488435858925096bc4ad7ba0";
    $method = 'GET';

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $this->url . $path);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
    $output = curl_exec($ch);
    $curl_error = curl_error($ch);
    curl_close($ch);

    return $output;
}

I can't give to you the correct URL, but the URL is working with Curl, so it should work with sockets.

I solved it by doing the following:

public function getUsers(){
    $path = "users/?accesstoken=c24f506fe265488435858925096bc4ad7ba0";
    $fp = fsockopen($this->url, 80, $errno, $errstr, 30);
    if (!$fp) {
        echo "$errstr ($errno)<br />
";
    } else {
        $out = "GET /{$path} HTTP/1.1
";
        $out .= "Host: {$this->url}
";
        $out .= "Connection: Close

";
        fwrite($fp, $out);
        while (!feof($fp)) {
            echo fgets($fp, 128);
        }
        fclose($fp);
    }
}

Connecting to a host via socket is not connecting to a URL.

Wrong: api.site.com.br/

Wrong: http://api.site.com.br/

Wrong: https//api.site.com.br/api/

Right: api.site.com.br

You connect to a host. This can be a domainname or an IP. Neither of those has a slash in it.