The Goal: to use a LAMP server to register as and endpoint to a SIP server.
Why: To intercept phone calls to a particular extension as they happen to interact with a PHP CRM.
The SIP server is not using Asterisk as has to be made generic enough to handle any SIP service.
I'm using a handy PHP SIP Library written by Level7Systems - Although there isn't many examples or support on this particular package.
My code is:
$api1 = new PhpSIP('x.x.x.x'); //My Servers public IP
$api1->setMethod('REGISTER');
$api1->setFrom('sip:111@my-dns.com');
$api1->setUri('sip:111@sip-server.com');
$api1->setUsername('12345');
$api1->setPassword('abc123');
$res = $api1->send();
The code executes successful, creates a socket (and a lock file), binds to a port and supposedly sends a UDP packet to the SIP server... Although, when I run a tcpdump
I don't see any UDP packets hitting port 5060 or 5061 to the destination server.
The code will run for 10 seconds while it waits for a reply from the SIP server as it should return with an 404 response. But it never does.
To be sure, I've also disabled my firewall.
Anyone had any experience registering a SIP endpoint using PHP?
Is there a better way to do it?
my suggestion is to add a try...catch to see what happens in your routine.
try {
$api1 = new PhpSIP('x.x.x.x'); //My Servers public IP
$api1->setMethod('REGISTER');
$api1->setFrom('sip:111@my-dns.com');
$api1->setUri('sip:111@sip-server.com');
$api1->setUsername('12345');
$api1->setPassword('abc123');
$res = $api1->send();
echo "res: $res\n";
} catch (Exception $e) {
echo $e->getMessage()."\n"; }
But, if you are using SIP phones, another solution is to try with the action URL / active URI. Here a good guide to understand how to use them.
So it turned out that @sip-server.com
wasn't actually an active SIP server.
It was more like @sip.sip-server.com
that needed to be pinged, and once that change happened, everything worked as expected.
Thanks.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.