Use $var when you want to manipulate values inside a route block, for example, when you want to store a value that will live only in the scope of that route block. When the route block exits, it will be automatically deallocated.
Use $avp when you want to store a value that you want to read anywhere. It will live as long as the SIP transaction lives.
- $var is stored in private memory, it is per process. This means that only the process that created it can read it.
- $avp is stored in shared memory. It can be accessed from any process in kamailio's process list (childs)
- $var has local route block scope.
- $avp has SIP transaction scope.
- Both $avp and $var are automatically freed.