Jump to content

Archived

This topic is now archived and is closed to further replies.

Ninjakreborn

Getting MLS data via RETS with PHP.

Recommended Posts

OK, I have done everything I can.  About 3-4 days worth of banging my head against the wall.  It's time to reach out for help..hopefully save myself some more headaches..

 

So a little run down. I have a client, who wants to get MLS data via RETS from a company.  The rets "data" is being provided by a company called "MLSpin".  I originally had

tried tapping into their old API which failed miserably, then found out they had upgraded and were using RETS.

 

So this is what I am trying to do.  At first I did the most logical thing and hunted down and RETS class in PHP. I found a few that sucked, a few that were outdated, then finally found a decent one.

http://troda.com/projects/phrets/index.php?title=Main_Page - This is the homepage to the RETS class that I found.

 

I downloaded it and installed it on the server.  I setup my configuration files, and got myself connected to my own database. Everything went find.

 

Then I spent about a day replicating the database on their server. Using a combination of code from their samples and custom code, I was able to strip down every table SQL schema they have on their server and replicate it locally.    Once that was out of the way I moved onto the next logical step...I started working on pulling over the data.

 

The client first wanted me to get all backlogged data from 7-1-2010.  From there until now, then set it up on a cron job to get it daily (get it at the end of each day (2 in the morning) for the previous day.

No problem I thought..so I started working on setting this all up for the first field of data. He wanted me to get single family, multi family, and condominium.  I first started with Single Family. After a lot of trial

and error I got a decently working script...but it works sporadically...I have tried tons of different date formats. I have tried getting it for a single day, for a single month, for a few days. Sometimes it runs

great sometimes it doesn't. I can't seem to get it to run consistently enough to get all the backlogged data, and certainly cannot get it to show the data from the past until now. I can't even get it to work properly

for just yesterday....

 

Sometimes it throws a 505 error, sometimes a memory error, sometimes it works (not sure how often..just randomly).

 

The INI file is here...http://www.benrealtygroup.com/info.php I had to fight with the host for a half a day to get more memory. I got the stats setup to give me as much memory and time as they allow during allocation....even with the extra memory it's having problems.

 

What I want to do is get the data one month at a time from 7-1-2010 all the way until now. I want to do this for Single Family, Multi Family, and Condo....then I want to set it up on a cron so it just gets the last updated fields every day..that's it... I can't see to get this to work. Right now I was working on Single Family.  Once I get all the backlogged data from it, I was going to set it up on the cron, and start working on multi family.

http://www.benrealtygroup.com/beta/crons/mls.php Here is the script I am working on.

 

Copied/Pasted below is the code I am using to implement the class and trying to get it to work.

<?php
/* GET MLS DATA ON CRON JOB */

// Required Files
require_once('../config/config.inc.php');
require_once("../config/phprets.php");

// Connection Settings
$rets_login_url = "###";
$rets_username = "###";
$rets_password = "###";

// Perform connection/setup class.
$rets = new phRETS;

$connect = $rets->Connect($rets_login_url, $rets_username, $rets_password);

/* HANDLE SINGLE FAMILY */
$resource = "RESI";
$class    = "SF";
//DATE IS Y-m-d
$search = $rets->SearchQuery($resource, $class, "UPDATE_DATE=2010-07-01");
$table_name = 'rets_' . strtolower($resource) . '_' . strtolower($class);


while ($listing = $rets->FetchRow($search)) {
// Check if LIST_NO exists...if it does, delete it.
$check = "SELECT * FROM " . $table_name . " WHERE LIST_NO = '" . $listing['LIST_NO'] . "'";
$query = mysql_query($check);
if (mysql_num_rows($query)) {
	mysql_query("DELETE FROM " . $table_name . " WHERE LIST_NO = '" . $listing['LIST_NO'] . "'");
}

$sql = "INSERT INTO " . $table_name;
$data_var = '';
$data_val = '';
foreach($listing as $key=>$value) {
	$data_var .= mysql_real_escape_string($key) . ', ';
	$data_val .= "'" . mysql_real_escape_string($value) . "', ";		
}
$data_var = substr($data_var, 0, -2);
$data_val = substr($data_val, 0, -2);
$sql .= ' (' . $data_var . ') VALUES (' . $data_val . ')'; 

if (mysql_query($sql)) {
	echo 'saved';
}else {
	echo 'not saved';
}
}
$rets->FreeResult($search);

/* HANDLE MULTI FAMILY */

?>

I have verified that it saves the data.  When I "am" able to get it to work...then I know the data saves...

 

As mentioned before it either throws a 505 (most of the time), or runs out of memory (some times), or works (rarely). I can't tell what makes it work and what doesn't. I have tried all forms of dates..one time I even

got an entire month with a lot of records to work.

 

Any help on getting this wrapped up would be very grateful.  This was around an 800 dollar job, but it's turning out to be very time consuming.

 

Thanks again.

Share this post


Link to post
Share on other sites

By the way. The host I am trying to do this on is Dreamhost.

 

But...I also tried to port my code to HostGator (who I have always been using for most of my clients)....

and for some reason I cannot even get it to connect to the MLS server in the first place at all.

 

The Dreamhost (when it does work) always at least makes the initial connection...host gator doesn't even get a connection at all

initially.

Share this post


Link to post
Share on other sites

I think I figured it out. I posted in another forum for Google Groups related to that class, I was advised to raise my max_execution_time to around 300. I am going to try having client upgrade hosts, and see if I can get the execution time that high. If it doesn't work, will post back here. If anyone else has more feedback, feel free to let me know.

Share this post


Link to post
Share on other sites

Hi businessman332211

 

I'm a PHP newbie. Could you please provide the sample of config.inc.php?

 

Thanks,

 

Bruce

Share this post


Link to post
Share on other sites

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.