Call Us Today! 877.742.2583

Page tree

Versions Compared


  • This line was added.
  • This line was removed.
  • Formatting was changed.


At it's basic level a variable simply gives a name to a piece of information, so instead of using something like you can create a variable named local_ip_v4, now whenever you need to specify an IP address, you can refer to this variable by using ${local_ip_v4} instead of typing the actual IP address. Variable values are stored in memory on your server, when you retrieve the variable FreeSWITCH pulls the current value from memory. There are several benefits to using variables.

  • Manage changes - by using a variable to define an IP address, you only specify the actual IP address once, then wherever you need the IP address you use the variable. If the IP address ever changes you just have to change it one place.
  • Readability - by giving a name to a specific value it's much easier to understand the configuration, for example if you would see a number 1000 in the configuration file it's not obvious what that number means is it an extension? Is it a timeout period? You wouldn't know. You would have to spend valuable time trying to get context from the surrounding text. By using a variable with a meaningful name you can avoid the guesswork.
  • Interacting with System – as we will see laterPassing Data - since FreeSWITCH is built on a modular architecture, variables provide a way for the different parts of FreeSWITCH to share dataconvenient way of sharing data between different modules
  • Configuration - the FreeSWITCH core and many modules have predefined variables that are used as configuration settings, these usually have a default value which you can override by setting the value of the variable. Used this way you can actually control the behavior of FreeSWITCH by changing the value of one of the predefined variables.


titleClick here to expand Table of Contents

Table of Contents

Global Variables

A global variable is used for data that's shared across the entire system and doesn't change oftenAs their name implies global variables are available to the entire FreeSWITCH system and the value is the same for all channels. It's intended to be used for variables that don't change often.

Global variables can be created/modified in the configuration using the set pre-processor command. You can also set a global variable using the global_setvar API command.

The FreeSWITCH core as well as some modules have many predefined variables, some of which are set in vars.xml in the default configuration, others have a default value assigned by the FreeSWITCH core. See the Global Variables page for a full list of predefined global variables.

Channel Variables

Channel variables are variables that are specific to a single channel such as Caller-Id-Number, Dialed-Number, etc. You can create a channel variable with the set application. Because channel variables are specific to a channel, they are only available in the context of a channel such as in the Dialplan, or in scripts running as part of a dialplan.

Retrieving Variables

Variables can be retrieved using the dollar syntax ${variable_name}. Wherever you use this syntax the FreeSWITCH engine will replace it with the current value of the variable. For global variables the value will be the same for all channels. Channel variables are only available in the context of a channel and will evaluate to the value for the current channel. For example in the dialplan you can create rules based on the destination_number channel variable. As the dialplan is evaluated for a channel, it will retrieve the dialed number for this particular channel.