All in vain

Some rants about technology, PHP, people, tools, web etc from a developers perspective. Feel free to copy ideas, code or anything from here.

Saturday, November 26, 2005

Accessing latest Betfair API through PHP

4 comments
Got succesful in accessing betfairs latest api in php. At first i tried using NuSoap webservice package but couldnt pull it off.

Then i saw someone do it in Perl by sending (Post?) Raw XML to
http://www.betfair.com/publicapi/BFService/

This is when i gave it a try in php and voila success! Here is what i did:


$user_agent = "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)";

$ch = curl_init(); // initialize curl handle
curl_setopt($ch, CURLOPT_URL, API_URL ); // set url to post to
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); // return into a variable
curl_setopt($ch, CURLOPT_TIMEOUT, 60); // times out after 1 min
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml ); // add POST fields

curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);

$header[] = "SOAPAction: ". API_URL;
$header[] = "MIME-Version: 1.0";
$header[] = "Content-type: text/xml; charset=utf-8";

curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
$result = curl_exec($ch); // run the whole process


if (curl_errno($ch))
{
print curl_error($ch);
return 0;
}
else
{

//now that we have got a result, parse this soap packet and return the XML doc
$parser = new soap_parser($result,'UTF-8','',TRUE);
$result = $parser->get_response();

//print_R($result);
curl_close($ch);

if($result["Result"]["header"]["errorCode"] != "NO_SESSION" )
{
update_session_key($result["Result"]["header"]["sessionToken"] );
}

return $result;
}
To this end i used the PatTemplate system to stuff values into the XML templates, and got the raw XML back. If anyone needs it i can supply the soap parser class i stole ;-). It was one of the class in NuSoap and just changed a few bits here and there.

Friday, November 25, 2005

i hate crons

No comments
Just when i thought i had cron jobs in control i lost it :-( , still banging my head...

Presto, its working again.... i forgot to send query string to a page you need to add "--get" in curl request. Basicaly i was calling a php script in cron and passing it parameters. One thing i thought would work was passing the query string in the URL itself which curl calls.

My mistake, now its fixed you call it with /usr/bin/curl -d "var1=adfdafs&var2=xyz" --get http://someurl.com/somefile.php

hurray,

Wednesday, November 23, 2005

Mysql fulltext indexing

1 comment
Just compiled sphinx, the mysql fulltext indexer. Compiling it was a breeze. And when i was stuck at a point, the original developer ( Andrew Aksyonoff, shodan [at] shodan.ru ) helped me out.

Must say OSS makes the world a better place to live in, Red Hat notwithstanding ;-)

Okay on sphinx, i indexed my table which had close to 700,000 rows of data (Blob), and it indexed it in under 100 secs!!. The provided api is good too (PHP and perl at the moment). But one thing it lacks, which i think should be there to make it a worthy replacement to mysql fulltext indexing itself is that you can not say +findme -leaveme in a search query.

Nevertheless it did show pretty neat results and it is one utility to watch out for. For more info visit: www.shodan.ru/projects/sphinx/