Search code examples
phpcurlretsphrets

PHP - Cant connect to RETS via PHRETS


I am trying to get all my MLS listing via PHP using PHRETS which I downloaded from here:

https://github.com/dangodev/PHRETS-Example/blob/master/lib/phrets.php

and I used this example to download my listings into a csv format:

https://github.com/troydavisson/PHRETS/wiki/Connect,%20download%20listing%20data%20in%20CSV%20format,%20disconnect

I got the RETS URL, username and password from my MLS board, but I still can’t connect.

My code returns false when call the PHRETS library here:

require_once("phrets.php");

// start rets connection
$rets = new phRETS;

echo "+ Connecting to {$rets_login_url} as {$rets_username}<br>\n";
$connect = $rets->Connect($rets_login_url, $rets_username, $rets_password);

if ($connect) {
        echo "  + Connected<br>\n";
}
else {
        echo "  + Not connected:<br>\n";
        print_r($rets->Error());
        exit;
}

When I goto to library and look at the method Connect, that code returns false here:

// make request to Login transaction
        $result =  $this->RETSRequest($this->capability_url['Login']);
        if (!$result) {
            return false;
        }

And when I look at my RETSRequest Method, it returns false here because the response code is 0 and not 200

if ($response_code != 200) {
            $this->set_error_info("http", $response_code, $response_body);
            return false;
        }

and here is where its trying to connect:

if ($this->ua_auth == true) {
            $session_id_to_calculate_with = "";

            // calculate RETS-UA-Authorization header
            $ua_a1 = md5($this->static_headers['User-Agent'] .':'. $this->ua_pwd);
            $session_id_to_calculate_with = ($this->use_interealty_ua_auth == true) ? "" : $this->session_id;
            $ua_dig_resp = md5(trim($ua_a1) .':'. trim($this->request_id) .':'. trim($session_id_to_calculate_with) .':'. trim($this->static_headers['RETS-Version']));
            $request_headers .= "RETS-UA-Authorization: Digest {$ua_dig_resp}\r\n";
        }

        $this->last_request_url = $request_url;
        curl_setopt($this->ch, CURLOPT_URL, $request_url);

        curl_setopt($this->ch, CURLOPT_HTTPHEADER, array(trim($request_headers)));
        // do it
        $response_body = curl_exec($this->ch);
        $response_code = curl_getinfo($this->ch, CURLINFO_HTTP_CODE);

Why can’t I connect?

I was able to login via http://retsmd.com with the url, username and password. I really need to get my listings in the format of CSV.

PLEASE HELP

I do have curl installed on my server, I checked with this method:

Check to see if cURL is installed locally?


Solution

  • A response code of 0 usually indicates that your server failed to open a connection with the server, likely due to firewall issues between you and them. Some RETS servers still run on a port 6103, so if your server (hosting company, etc.) prevent outbound connections from being opened on that port, that could be the cause for what you're seeing.

    I'd recommend trying your code example from a different server or computer that doesn't have any connection restrictions. You could also try https://retsmd.com/auth as a way to verify that the credentials you've been given will work (assuming your local environment has what it needs for PHRETS to run).