Events in practice
Let's look at a few specific examples that demonstrate the use of events.
Event Socket Library example – running a command
The following PHP example shows how you can write a simple script to process one-line commands. Using the FreeSWITCH Event Socket Library you can send those commands to FreeSWITCH and wait for the response.
// Include FreeSWITCH ESL Library. Note that ESL.php comes // with the FreeSWITCH PHP ESL module. require_once('ESL.php'); if ($argc <= 1) { printf("ERROR: You Need To Pass A Command\nUsage:\n\t%s <command>", $argv[0]); exit(); } // Strip off the executable's name ($argv[0]) array_shift($argv); $command = sprintf('%s', implode(' ', $argv)); printf("Command to run is: %s\n", $command); // Connect to FreeSWITCH $sock = new ESLconnection('localhost', '8021', 'ClueCon'); // Send the Command $res = $sock->api($command); // Print the response printf("%s\n", $res->getBody());
Examples of sending events to FreeSWITCH
The following examples...