Hello, I am trying to create PHP application that will be receiving information about each call from freeswitch and send commands to control freeswitch. I found an example at https://wiki.freeswitch.org/wiki/PHP_ESL#ivrd BUT unfortunately they do not explain how I can retrieve information from freeswitch (so I can do the routing in PHP). I guess I should use PHP ESL but the documentation is pretty bad so if someone has some working example, I'd appreciate it. I tried to read from stdin this way: *#!/usr/bin/php -q <?php // set a couple of things so we dont kill the system ob_implicit_flush(true); set_time_limit(30); // Open stdin so we can read the data in $in = fopen("php://stdin", "r"); // Connect echo "connect\n\n"; // READ DATA $text = fgets($in); file_put_contents('/usr/local/freeswitch/scripts/socketlog.txt' ,$text, FILE_APPEND); // Answer echo "sendmsg\n"; echo "call-command: execute\n"; echo "execute-app-name: answer\n\n"; // Play a prompt echo "sendmsg\n"; echo "call-command: execute\n"; echo "execute-app-name: playback\n"; echo "execute-app-arg: /usr/local/freeswitch/sounds/en/us/callie/ivr/8000/ivr-welcome_to_freeswitch.wav\n\n"; // Wait sleep(5); // Hangup echo "sendmsg\n"; echo "call-command: hangup\n\n"; fclose($in); ?>* *Unfortunately, everything I get as a result in my log file is:* *Event-Name: CHANNEL_DATA*
I'll have to defer to those who know PHP better than I, but my first question would be: does fgets read all data off the input buffer or does it read one line at a time? -MC On Wed, Jul 10, 2013 at 3:23 AM, Milos Jovanovic < development.milos@gmail.com> wrote:
Hello,
I am trying to create PHP application that will be receiving information about each call from freeswitch and send commands to control freeswitch.
I found an example at https://wiki.freeswitch.org/wiki/PHP_ESL#ivrd BUT unfortunately they do not explain how I can retrieve information from freeswitch (so I can do the routing in PHP).
I guess I should use PHP ESL but the documentation is pretty bad so if someone has some working example, I'd appreciate it.
I tried to read from stdin this way:
*#!/usr/bin/php -q
<?php
// set a couple of things so we dont kill the system ob_implicit_flush(true); set_time_limit(30);
// Open stdin so we can read the data in $in = fopen("php://stdin", "r");
// Connect echo "connect\n\n";
// READ DATA $text = fgets($in); file_put_contents('/usr/local/freeswitch/scripts/socketlog.txt' ,$text, FILE_APPEND);
// Answer echo "sendmsg\n"; echo "call-command: execute\n"; echo "execute-app-name: answer\n\n";
// Play a prompt echo "sendmsg\n"; echo "call-command: execute\n"; echo "execute-app-name: playback\n"; echo "execute-app-arg: /usr/local/freeswitch/sounds/en/us/callie/ivr/8000/ivr-welcome_to_freeswitch.wav\n\n";
// Wait sleep(5);
// Hangup echo "sendmsg\n"; echo "call-command: hangup\n\n";
fclose($in);
?>*
*Unfortunately, everything I get as a result in my log file is:*
*Event-Name: CHANNEL_DATA*
_________________________________________________________________________ Professional FreeSWITCH Consulting Services: consulting@freeswitch.org http://www.freeswitchsolutions.com
FreeSWITCH-powered IP PBX: The CudaTel Communication Server http://www.cudatel.com
Official FreeSWITCH Sites http://www.freeswitch.org http://wiki.freeswitch.org http://www.cluecon.com
FreeSWITCH-users mailing list FreeSWITCH-users@lists.freeswitch.org http://lists.freeswitch.org/mailman/listinfo/freeswitch-users UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users http://www.freeswitch.org
-- Michael S Collins Twitter: @mercutioviz http://www.FreeSWITCH.org http://www.ClueCon.com http://www.OSTAG.org
Hi.
From the php manual: Reading ends when length - 1 bytes have been read, or a newline
Link: http://www.php.net/fgets This should work: while(!feof($in)) { $text = fgets($in); file_put_contents('/usr/local/freeswitch/scripts/socketlog.txt' ,$text, FILE_APPEND); } Denis ----- Messaggio originale ----- Da: "Michael Collins" <msc@freeswitch.org> A: "FreeSWITCH Users Help" <freeswitch-users@lists.freeswitch.org> Inviato: Mercoledì, 10 luglio 2013 19:05:01 Oggetto: Re: [Freeswitch-users] PHP ESL & Event Socket Outbound I'll have to defer to those who know PHP better than I, but my first question would be: does fgets read all data off the input buffer or does it read one line at a time? -MC On Wed, Jul 10, 2013 at 3:23 AM, Milos Jovanovic < development.milos@gmail.com > wrote: Hello, I am trying to create PHP application that will be receiving information about each call from freeswitch and send commands to control freeswitch. I found an example at https://wiki.freeswitch.org/wiki/PHP_ESL#ivrd BUT unfortunately they do not explain how I can retrieve information from freeswitch (so I can do the routing in PHP). I guess I should use PHP ESL but the documentation is pretty bad so if someone has some working example, I'd appreciate it. I tried to read from stdin this way: #!/usr/bin/php -q <?php // set a couple of things so we dont kill the system ob_implicit_flush(true); set_time_limit(30); // Open stdin so we can read the data in $in = fopen("php://stdin", "r"); // Connect echo "connect\n\n"; // READ DATA $text = fgets($in); file_put_contents('/usr/local/freeswitch/scripts/socketlog.txt' ,$text, FILE_APPEND); // Answer echo "sendmsg\n"; echo "call-command: execute\n"; echo "execute-app-name: answer\n\n"; // Play a prompt echo "sendmsg\n"; echo "call-command: execute\n"; echo "execute-app-name: playback\n"; echo "execute-app-arg: /usr/local/freeswitch/sounds/en/us/callie/ivr/8000/ivr-welcome_to_freeswitch.wav\n\n"; // Wait sleep(5); // Hangup echo "sendmsg\n"; echo "call-command: hangup\n\n"; fclose($in); ?> Unfortunately, everything I get as a result in my log file is: Event-Name: CHANNEL_DATA _________________________________________________________________________ Professional FreeSWITCH Consulting Services: consulting@freeswitch.org http://www.freeswitchsolutions.com FreeSWITCH-powered IP PBX: The CudaTel Communication Server http://www.cudatel.com Official FreeSWITCH Sites http://www.freeswitch.org http://wiki.freeswitch.org http://www.cluecon.com FreeSWITCH-users mailing list FreeSWITCH-users@lists.freeswitch.org http://lists.freeswitch.org/mailman/listinfo/freeswitch-users UNSUBSCRIBE: http://lists.freeswitch.org/mailman/options/freeswitch-users http://www.freeswitch.org -- Michael S Collins Twitter: @mercutioviz http://www.FreeSWITCH.org http://www.ClueCon.com http://www.OSTAG.org _________________________________________________________________________ Professional FreeSWITCH Consulting Services: consulting@freeswitch.org http://www.freeswitchsolutions.com FreeSWITCH-powered IP PBX: The CudaTel Communication Server http://www.cudatel.com Official FreeSWITCH Sites http://www.freeswitch.org http://wiki.freeswitch.org http://www.cluecon.com FreeSWITCH-users mailing list FreeSWITCH-users@lists.freeswitch.org http://lists.freeswitch.org/mailman/listinfo/freeswitch-users UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users http://www.freeswitch.org
Hi, This works for me with PHP and outbound socket. Dialplan: *** sends connection to IP A.B.C.D port 8084 <extension name="test"> <condition field="destination_number" expression="^\*\*\*$"> <action application="socket" data="A.B.C.D:8084"/> </condition> </extension> xinetd picks up the connection and sends to the script. xinetd config is: *service unlisted { user = whoever disable = no type = UNLISTED socket_type = stream protocol = tcp wait = no server = /home/test/test.php port = 8084 server_args = HOST } * The php script picks it up from there #!/usr/bin/php <?php require_once('ESL.php'); $esl = new ESLconnection(0); $ans= $esl->execute('answer'); $subscribe = $esl->sendRecv('myevents'); $subscribe = $esl->sendRecv('linger'); # Without this the channel closes before we receive the events $res = $esl->execute('sleep', '1000'); $context = $esl->getInfo()->getHeader('Caller-Context'); $curr_user = $esl->getInfo()->getHeader('variable_sip_from_user'); $curr_host = $esl->getInfo()->getHeader('variable_sip_from_host'); ///etc etc. Hope that helps Mike On Wed, Jul 10, 2013 at 11:23 AM, Milos Jovanovic < development.milos@gmail.com> wrote:
Hello,
I am trying to create PHP application that will be receiving information about each call from freeswitch and send commands to control freeswitch.
I found an example at https://wiki.freeswitch.org/wiki/PHP_ESL#ivrd BUT unfortunately they do not explain how I can retrieve information from freeswitch (so I can do the routing in PHP).
I guess I should use PHP ESL but the documentation is pretty bad so if someone has some working example, I'd appreciate it.
I tried to read from stdin this way:
*#!/usr/bin/php -q
<?php
// set a couple of things so we dont kill the system ob_implicit_flush(true); set_time_limit(30);
// Open stdin so we can read the data in $in = fopen("php://stdin", "r");
// Connect echo "connect\n\n";
// READ DATA $text = fgets($in); file_put_contents('/usr/local/freeswitch/scripts/socketlog.txt' ,$text, FILE_APPEND);
// Answer echo "sendmsg\n"; echo "call-command: execute\n"; echo "execute-app-name: answer\n\n";
// Play a prompt echo "sendmsg\n"; echo "call-command: execute\n"; echo "execute-app-name: playback\n"; echo "execute-app-arg: /usr/local/freeswitch/sounds/en/us/callie/ivr/8000/ivr-welcome_to_freeswitch.wav\n\n";
// Wait sleep(5);
// Hangup echo "sendmsg\n"; echo "call-command: hangup\n\n";
fclose($in);
?>*
*Unfortunately, everything I get as a result in my log file is:*
*Event-Name: CHANNEL_DATA*
_________________________________________________________________________ Professional FreeSWITCH Consulting Services: consulting@freeswitch.org http://www.freeswitchsolutions.com
FreeSWITCH-powered IP PBX: The CudaTel Communication Server http://www.cudatel.com
Official FreeSWITCH Sites http://www.freeswitch.org http://wiki.freeswitch.org http://www.cluecon.com
FreeSWITCH-users mailing list FreeSWITCH-users@lists.freeswitch.org http://lists.freeswitch.org/mailman/listinfo/freeswitch-users UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users http://www.freeswitch.org
participants (4)
-
Denis Gasparin
-
Michael Collins
-
Mike Raistrick
-
Milos Jovanovic