Variable Scope Questions

I have a few questions about how Variables work within Asterisk 1.6, and what the scope of them are:

  1. Global Variables – I understand that these are global across all calls, but my question is that if I have 3 calls running concurrently and one call makes a change to the global variable does it propogate to the other active calls or only new calls?

  2. Variables created with Set() – I am working on an IVR that interacts with MS SQL via AGI and PHP/PHP-ODBC. Basically what I have done is taken each menu of the IVR and placed it in it’s own context in extensions.conf. When a call comes in the first thing I do is initiate a call creates a record in a table, and passes a Key back to Asterisk to stay with this call.

Question: Should a variable set at the biggining of this call be valid across all contexts? Would these variables remain valid if I use dial() to make an outgoing call during these scripts?

(1) changing the value will take effect immediately so i would say results are going to be unpredictable since it will depend on where the other calls are in the dial plans in relationship to retrieving and using the value of that variable. the more interesting question seems to me what happens if all three of the concurrent calls make changes to the same variable.

(2) from voip-info.org/wiki/view/Asterisk+cmd+Set:

[quote]When setting variables, if the variable name is prefixed with _, the variable will be inherited into channels created from the current channel. If the variable name is prefixed with __, the variable will be inherited into channels created from the current channel and all children channels. [/quote].

#1) I was pretty sure that is how globals work, so I hadn’t planned around that idea.

#2) I had read through how set worked, and I think my problem in understanding what is being said in the quoted text is a lack of understanding of channels (I think).

I’m gonna try to express how I understand what is happening in my system, and how this would relate:

I setup a DID for testing of my scripts, when you call the DID, you are prompted by a menu most options just play audio files, but the option I am having issues with does the following:

dial number entered with macro for call screening by destination number> This is where I am having issues.

So the way I understand the channels right now, I have Channel01 which is the DID channel for the incoming call. Then when I begin dialing the destination I have Channel02 right?

So if my assumption of the above Channel are right, creating ${CDRGUID} in Channel01, it is only valid in Channel01. BUT if I create $(_CDRGUID} it will be valid in both Channel and Channel02? I’m not sure where I would use children channels, but I assume that if for some reason channel02 had to also dial out again it would be the situation.