You are here

PHP SIP API

More how-tos to help me remember:

Google Code has a PHP class written for SIP. It enables you to send CANCEL, NOTIFY, INVITE, BYE, REFER, OPTIONS, SUBSCRIBE, MESSAGE, and REGISTER messages to a SIP endpoint.

I am using it to monitor:

1. A couple of Asterisk servers that don't take registrations via OPTIONS
2. A couple of OpenSIPS servers that do take registrations.

The documentation is located at: http://code.google.com/p/php-sip/

Following is a sample PHP script that I run on a cronjob:


#!/usr/bin/php
<?php
require_once('PhpSIP.class.php');

if ( isset($argv[7]) ) {
$ip = $argv[1];
$pause1 = $argv[2];
$pause2 = $argv[3];
$user = $argv[4];
$password = $argv[5];
$domain = $argv[6];
$method = $argv[7];
} else {
echo $argv[0] . " \n";
exit;
}

sleep($pause1);

try
{
$api = new PhpSIP();
$api->setUsername($user); // authentication username
$api->setPassword($password); // authentication password
$api->setProxy($ip);
// $api->addHeader('Event: resync');
if ( $method === 'REGISTER' ) $api->addHeader('Expires: 3600');
$api->setMethod($method);
$api->setFrom('sip:'.$user.'@'.$domain);
$api->setUri('sip:'.$user.'@'.$domain);
$time_start = microtime(true);
$res = $api->send();
$time_end = microtime(true);
$time = $time_end - $time_start;

sleep($pause2);
printf ("%s, %-20s, %.3fs, %s %s", date('c'), $ip, $time, $res, $method);

} catch (Exception $e) {

echo $e;
}
?>

Contact Us if you would like me to help you work up something for your system. For instance, you could build a Web Page with a "click-to-call" link on it.

User login