Video Chat - Documentation

Video Chat

Thank you for purchasing videochat PHP script based on OpenTok API. If you have any questions that are beyond the scope of this help file, please feel free to email Thanks so much!



Note. You can view framework's requirements by accessing the requirement checker script via the following URL in a Web browser: 

OpenTok registration

1. Register OpenTok account
2. Go to "projects" section ( You will find your API Key and API Secret under the project name.
API Secret API Key
3. Next we need to fill out opentok config. To do this open:
return array(
    "API_KEY"=>"", // Replace this value with your OpenTok API Partner Key
    "API_SECRET"=>"", // Replace this value with your OpenTok API Partner Secret

Database settings

All application settings located in 


Let's begin with connection to the database. Open config file and modify following lines with your mysql credentials.


   // Mysql with host: localhost and databse name: videochat
   'connectionString' => 'mysql:host=localhost;dbname=videochat',

   // whether to turn on prepare emulation
   'emulatePrepare' => true,

   // db username
   'username' => 'root',

   // db password
   'password' => '',

   // default cahrset
   'charset' => 'utf8',

   // table prefix
   'tablePrefix' => 'ca_',

    // cache time to reduce SHOW CREATE TABLE * queries
    'schemaCachingDuration' => 60 * 60 * 24 * 30,

Cron jobs

This app very closely linked with cron jobs, because it has to clear expired sessions, messages, notifications and etc.
You have possibility to do this in two different ways: via command line or using 3rd party services to run command via browser.
1. Let's begin with command line:
All you need is to add following line into your cron job shedule.
* * * * * /usr/bin/php /path/to/web/root/protected/clearsession.php >/dev/null 2>&1
* * * * * Time and date for your task. In our case cron will be executed every 1 minute
/usr/bin/php path to php command
/path/to/web/root/protected/clearsession.php physical path to script
>/dev/null 2>&1 this mean that all output from this command should be shoved into a black hole. I.e just do nothing with output.


2. Using 3rd paty service as cron job:
There is a lot of 3rd party services you can find, which will send requests to defined URL every N minutes.
Open config file and find following line:
'clearKey' => false,
Set up your sicret key (ex. "abc")
'clearKey' => 'abc',
Now, to clear expired data you need request this URL:
Pay attention! GET variable "key" must be equal to what you have set in config file. In our case it's "abc"
Note. If you installed script in sub-direcotry, then URL should look like this:

Remains only register this URL in your 3rd party service.


Resource usage

You must have enough resources to run this application. For example, free hosting is hardly suitable for this purpose, because
information about users is constantly updated in real time. However, we can manipulate this process. Let's take a look how.
In config we have following settings for this needs:
'sessIntTime' => 50 * 1000, // Milliseconds 50 * 1000 ms == 50 sec
'dataSync' => 5 * 1000, // Milliseconds. Informer and online users
'chatActivity' => array(
  // NoActivity => Time between requests
  0  => 1 * 1000,
  3  => 2 * 1000,
  10  => 5 * 1000,
  20 => 15 * 1000,
  30 => 30 * 1000,
Time in milliseconds. When user talking face-to-face he is not active and session on the server can expire.
To prevent this, we send request each 50 seconds, to handle user online.
dataSync Time in milliseconds. After each 5 seconds script updates user list and notifications which has been sent to user.
This array controls chat activity. The algorithm is very straightforward.
When user do not recieves new messages after 3 requests. (in our case first 3 requests repeates every 1000 milliseconds)
The next 7 requests will be repeated every 2 seconds and etc.
Therefore we can save resources and traffic. If user just talking and not sending messages the chat will be in passive mode.


Note: When user send message, the counter is reset.
Note: If you want get maximum perfermance, leave only 1st elemnt in array. ex:
'chatActivity' => array(
  0 => 1 * 1000



You can translate or modify interface language as you want. To do this open:
You will find an key=>value array. Replace values with your phrases. For example:
"Username" => "My custom username",



To prevent time dissynchronization between PHP and MySQL servers,  this application uses timezone defined in config file. Find your suitable timezone here
In config:
'default_timezone' => 'Europe/Vilnius',


Q:  How to change app name?
A:   You can change app name in config file

'name'=>'Free VideoChat',


Q:   Something does not work? What to do?
A:   All errors are logged in 

Contact me by email and don't forget to send me this file.

This app is built using OpenTok platform. Today (2013-09-01) they provide unlimited number of minutes for "face-to-face" video chat . I am not responsible if in the future they will close this service or make its paid.