Mitel 5000 PHP SMDR Script

You may have read my short writeup about reading SMDR from the Mitel 5000 with a simple PERL script. If not you can see it HERE.

This script is basically the same thing but in PHP. You will have to setup PHP to run from the CLI for this to work… I also set the execution time really long and could run it from a web page as well. It was really ugly but this gets the idea out there…

 
#!/usr/bin/php
<?php
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
socket_connect($socket, '1.2.3.4', 4000);
 
socket_write($socket, chr(2),1);
usleep(5);
socket_write($socket, chr(0) . chr(0) . chr(0),3);
usleep(5);
socket_write($socket, chr(132) . chr(0),2);
while(true){
	$data = socket_read($socket,512);
	if($data){
		echo $data;
		unset($data);
	}
	sleep(5);
}
 
?>
This entry was posted in PHP, Scripts, Telephony and tagged , . Bookmark the permalink.

4 Responses to Mitel 5000 PHP SMDR Script

  1. Hadlee says:

    This is so amazing. Its exactly what im looking for, get the raw data. Now I just need to output it properly or the way I want. Thank you, I’ve been searching for a purely PHP based way and all I could find previous to this was Perl, Perl and more Perl!

    10/10

  2. Hadlee says:

    If you have any more information about this or can point me into the right direction I’d be very grateful. I’m having trouble with getting every call that is made even when manually stop/starting the script and it hangs when there is no data. Anything please 🙂

    • schaeffer says:

      Unfortunately I don’t have one of these systems to test against anymore… I suspect the TCP session is timing out in some way. I actually use a trial version of another application to reverse engineer the process to write the PHP script. You may have to generate some type of TCP keep alive to keep the connection open longer term.

    • schaeffer says:

      How long is the script running before it times out and drops the connection?

Leave a Reply

Your email address will not be published. Required fields are marked *