[Freeswitch-users] Outbound socket PHP question

William Suffill william.suffill at gmail.com
Tue Aug 4 16:04:08 PDT 2009

I wrote some notes on this but have yet to wiki it.

example of an outbound socket connection where the call is answered, a
variable is set then perhaps play one of the pre-installed files and

fs_ivrd comes with freeswitch. It being a small daemon just invokes
the script defined in a variable and passes data from it via STDIN/OUT

Since this is an outbound socket connections it needs to be defined in
the dialplan.


<extension name="outbound-socket">

    <condition field="destination_number" expression="^55(522)$">

        <action application="set"

        <action application="socket" data=" async full"/>



The above dialplan sample would invoke ivr-demo.php when 55522 is
called as long as fs_ivrd is running. To start fs_ivrd:

/usr/local/freeswitch/bin/fs_ivrd -h -p 8004

It takes 2 arguments -h for hostname and -p for port.

PHP Code

#!/usr/bin/php -q


    // set a couple of things so we dont kill the system



    // Open stdin so we can read the AGI data in

    $in = fopen("php://stdin", "r");

    // Connect

    echo "connect\n\n";

    // 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:

    // Wait


   // Hangup

   echo "sendmsg\n";

   echo "call-command: hangup\n\n";



ivrd will call this script for each call. All itdoes is answer the
channel tell FreeSWITCH to play the “welcome to freeswitch” prompt.
Since the script is now controlling all call flow I needed to add a
wait or it would send the hangup immediately before the prompt was

Some improvements possible but that's 1 way to do it. It would be
possible to do the socket directly in PHP but fs_ivrd is a nice option

-- W

More information about the FreeSWITCH-users mailing list