Brice Stacey home

PHP-SIP Client Released

Earlier this year I investigated how Standard Interchange Protocol (SIP) was actually used for consortial borrowing. It's one of those protocols that is often spoken of, but I'm sure few could tell you much about. That scared me, so I wanted to learn more.

After I got my hands on a copy of the specs and was able to connect and send messages to our SIP server, I was incredibly excited about the possibilities. So I put together a quick PHP-SIP Client that I am now hosting on github.

Before sending any SIP messages, you have to login. Here is an example snippet on how to log in.

<?php
$socket = sipapi_connect('sip.example.com', '7031');
$fields = array(
    'UIDAlgorithm' => '0',
    'PWDAlgorithm' => '0',
    'CN' => 'insert_username',
    'CO' => 'insert_password',
    'CP' => 'insert_location',
  );
$msg = sipapi_msg93($fields);
$response = sipapi_send_message($socket, $msg);
print_r($response);
?>

Once you've successfully logged in, you can lookup a patron with the following snippet:

<?php
$fields = array(
    'Language' => '001',
    'Summary' => '',
    'AO' => 'drupalcirc',
    'AA' => 'insert_patron_identifier',
    );
$msg = sipapi_msg63($fields);
$response = sipapi_send_message($socket, $msg);
print_r($response);
?>

You can download the client at the PHP-SIP github repository.

Code is not fool-proof, but it works. Comments and collaborators welcome.