PetFinder API PHP Class Library

I was interested in a project for a website as to what data could be retrieved from To my surprise, on their website located in the footer is a link to their API documentation. In order to use their API, you must first fill out a developer request for a key & password. I did a quick look to see if anyone had written a php class for accessing the api, but couldn’t find anything useful. I have created a php class that you can call the certain methods available to retrieve the records.

Update 6-30-2010:

I recently updated the class to enable caching the xml response from the Petfinder server. This should provide a nice little speed boost even though it was already pretty fast :). Caching is enabled by default, and caches expires in 3 minutes. The folder “cache_files” in zip folder must have write permissions. As shown in the instructions, you can change the paths of cache files.

This class will parse the returned xml as a data array. This libary requires just 4 easy steps to get data:

  1. Add api-password to class
  2. Add api-key to class
  3. Pass configuration values as an array
  4. Call the method in the class

Here is an example of how to use the php class

include_once('class.petfinder.php'); //include class
$pet = new Petfinder(); //create Petfinder object
$pet->setKey('12345'); //your api-key
$pet->setPass('abcdef'); //your api-secret
$pet->set(array('cache_expire' => 360)); //(optional) Time in secs to expire  default shown
$pet->set(array('cache_path' => 'full_path_to_cache_folder')) //(optional) Set cache path 
$pet->set(array('cache_enable' => FALSE)); //(optional) Disable cache feature 
$config = array('location '=> '44805', 'animal' => 'dog'); //associative array of values to pass to class. array keys must match arguments from API
$pet->initialize($config) //pass values to the class
$data = $pet->petFind(); //call API method which are accessed by camel casing them (pet.find=petFind)

The xml data is returned as an associative array. The array has been mapped to the xml layout returned by PetFinder. Echo out the variable and you will see the returned status code, the array of returned values, and the xml response data from PetFinder.


If you would like to donate, you may do so by using Paypal.