SMS Gateway software
Ozeki brings you outstanding
SMS Gateway technology. Use our SMS Server products on Windows,Linux, or Android

Developers can use our C# SMS API to send SMS from C#.Net. The C# SMS API comes with full source code

The ozeki PHP SMS gateway software can be used to send SMS from PHP and to receive SMS usig PHP on your website

SMPP SMS Gateway
SMS service providers use our SMPP gateway solution, that offers a high performance SMPP server and SMPP client gateway with amazing routing capabilities
Ozeki Phone System

PHP VoIP developers 101

Part 2: PHP example on recording VoIP calls, call routing

The Ozeki Phone System gives you the opportunity to use its special features. If you have any problems how to log calls, record or route them, do not hesitate to read this guide. All the answers are in it, and far more information about it.


On the previous page the first part of PHP VoIP developers 101 could be read. That guide presented the prerequisites of doing basic tasks, such as SMS sending/receiving or making/receiving a call using your own PHP application. This article focuses on far more advanced features, like call logging, call recording and call routing.

Part 1: PHP example on sending SMS, making VoIP calls

Getting started

First of all, install a web server, MySql and PHP to your PC. The easiest way to do this, is installing Xampp package which includes Apache web server, MySql with a GUI, PHPMyAdmin and PHP. You can download it from here.


After installing Xampp, you can reach PHPMyAdmin at 'localhost/phpmyadmin'. Databases of MySql are availabe here. Username is "root" and password is empty by default. Creating a new database is available on the Databases tab.

After you create a database, create a table where you can record log entries of incoming calls. First, you need to choose the desired database. Then choose columns and create the table.

SQL Scripts

Creating a database:


Code example 1 - SQL commands to create a new database

Creating a table:

    CallID VARCHAR(50),
    CallState VARCHAR(50),
    Caller VARCHAR(50),
    CallerID VARCHAR(50),
    Callee VARCHAR(50),
    NotificationName VARCHAR(50),

Code example 2 - SQL commands to create a table

Inserting into the table:

INSERT INTO calls(CallID, 

Code example 3 - SQL commands to insert data

Query number of successful calls:

SELECT COUNT(*) FROM calls WHERE CallState = "Completed"

Code example 4 - SQL commands to query number of calls

1. Log calls

To log calls, you must change the settings at PBX, Productivity menu, http API menu item where you need to give a URL and select which script is executed if call status changes. In this case it is a PHP script.

First, PHP script read the call data:

$CallState = $_POST['CallState'];
$CallId = $_POST['CallId'];
$Caller = $_POST['Caller'];
$CallerId = $_POST['CallerId'];
$Callee = $_POST['Callee']; 
$NotificationName = $_POST['NotificationName'];

Code example 5 - PHP commands to change status

Then it makes a connection with the database server. It is possible because of the calling mysql_connect function. There are 3 arguments: the first is the name of database, second is the username and the third is the password. If the connection is successfully created, choose the desired database by calling the mysql_select_db function. To insert data you can use the mysql_query function. The function execute the instruction which was given in arguments, in this case that is an INSERT INTO instruction.

INSERT INTO calls(CallID, 

Code example 6 - SQL commands to set calls

After you insert it, close the MySQL connection with mysql_close function.

Making queries

First, you need to join to MySQL server, and then choose the database with the instruction above. To make queries, you can also use the mysql_query function, however to process queries, use the mysql_fetch_array function, and it will make the records (which were given back by the query) into an array. By using the mysql_query argument function you request the return code.

2. Record calls

PBX can record the calls. For this, use your Call changed URL. So, the entered script can start the recording with an instruction. The attribute of the finshedUrl is the URL which gets the URL address from the record. You can choose the format of recording (mp3 or wav) in format attribute. Please change the ozekixepbx.ip text to the ip address where the Ozeki Phone System XE is installed. On yoursite.com the address should be the same as where the sample applications are running.

	<Record finishedUrl="http://yoursite.com/Recording.php" format="mp3"/>

Code example 7 - XML commands to reponse settings

By the end of the call, PBX sends the URL of record to the script which was given in finishedUrl. First, script read the data. Then write them into Records table, CallRecords, MySQL database.

$CallID = $_POST['CallId'];
$Success = $_POST['Success'];
$Duration = $_POST['Duration'];
$Caller = $_POST['Caller'];
$Callee = $_POST['Callee'];
$RecordURL = $_POST['RecordURL'];
$NotificationName = $_POST['NotificationName'];

Code example 8 - PHP commands to call recording

SQL Scripts

Creating a new database:


Code example 9 - SQL commands to create a new database

Creating a new table:

    CallID VARCHAR( 50 ) ,
    Succes VARCHAR( 50 ) ,
    Duration INT,
    Caller VARCHAR( 50 ) ,
    Callee VARCHAR( 50 ) ,
    RecordURL VARCHAR( 255 ) ,
    NotificationName VARCHAR( 50 ) ,

Code example 10 - SQL commands to create a new table


INSERT INTO records(CallID, 
"9998", 	   "http://ozekixepbx.ip:7780/HttpRecordings/437c53e702454a01b8e3f8caa0824d85.mp3", "RecordCompleted")

Code example 11 - SQL commands to inster data

Query all records:

SELECT * FROM records

Code example 12 - SQL commands to make queries

3. Call routing

Besides Dial Plan, it is possible to give a PHP method, so you can decide which extension answers the call when forwarding your calls. If you did not forward the call, it will be handle by the rules of Dial Plan. You can enter into the Route interception URL field the path of your method (e.g. http://yoursite.com/RouteCalls/RouteCall) in the Productivity menu's, HTTP API submenu. PHP script reads the call data:

$NotificationName = $_POST['NotificationName'];
$CallerID = $_POST['CallerID'];
$OriginalDialedNumber = $_POST['OriginalDialedNumber'];
$LastDialedNumber = $_POST['LastDialedNumber'];
$LastCalledExtension = $_POST['LastCalledExtension'];
$LastCallState = $_POST['LastCallState'];
$CallerExtension = $_POST['CallerExtension'];

Code example 13 - PHP commands to set call routing

When there is a call for extension 9999 and it is forwarded to extension 1100 and waits just one second.

	<Route RingTime = "1" Destination="1100"/>

Code example 14 - XML commands to forward calls

If there was no answer to the previous call or line was occupied, call is forwarded to extension 9998:

	<Route Destination="9998"/>

Code example 15 - XML commands to forward calls

RingTime attribute is optional, it is 90 by default. If you do not want to forward the call, enter an empty string, so the rules of dial plan work. You can read more about Route command here.

Part 1: PHP example on sending SMS, making VoIP calls

If you have any questions or need assistance, please contact us at info@ozekiphone.com