Dialparties.agi how it work? and why it work in this way?

This AGI is fire every dial, so it’s seem strange that make login into the Manager again and again? there no way to do this work more efficient?

Why this code not wrote in Dialplan instead?

And how it’s prevent problem with multi threading? Think about Extension with inactive Call Waiting setting, So one call start for Ex 203, the ialparties.agi check the Status of 203 and return that is “available”, Now the system move to another thread that start another call to 203, the dialparties.agi again and return “available”, so the dial start. Now the system continue the first Thread and make another dial into 203?

So how FreePBX prevent situation like that?

the answer to your first question, one of the original reasons (years ago) that dialparties was introduced was because of the need to go through the manager to get the extension state (vs. the device state which can be done with no AGI/manager call).

For non-ringgroup dialing, one might be able to either simplify dialparties by providing an alternative, simpler script or trying to move it all into the dialplan, although you would have to work around the ‘extension state’ issue still, since single extensions can still have multiple devices associated with them.

As far as the race condition you describe, there is nothing that prevents it from occurring. If it were of real concern, it would have to be dealt with whether implemented in an AGI script or in dialplan. However, there has not been any concern for that scenario for several reasons. For starters, the vast majority of installations implement SIP based multi-line appearance phones and have CW enabled. In the cases that the phone can’t handled multiple calls, most phones will simply result in a busy signal being sent back resulting in the same behavior. For the remaining small percentage of cases where an accidental second call might be delivered to the phone when not desired, then it is theoretically possible that the described scenario could happen. Then end result is far from critical and the likelihood is extremely improbable. Thus, there is no concern that the race condition is present.

The overhead of calling to AGI and login into Manager is not justify to move this work into Core of Asterisk or at lest to Dialplan(specially for heavy system)?

About the option of moving it to Dialplan, I have a long time question how do that? I not see that Asterisk 1.4 support Atomic code on dial plan (the exclusive macro is not solution for this need). rather then i not sure that one line on dial plan is atomic?

So even you right refer to the WC that not critical, I have guess that have another situation of critical need. so even is good practice to avoid this need what we do if need is emerge?

And also for CW, what I do if I build service on Astrisk and I gave to my customer option for inactive CW, or I work with Call Centre and i must ensure that this situation not happen? How I do that?

I’ve read some years ago that it’s not suggested to use a direct connection to the manager if you plan to log on and off frequently. One should use a proxy instead which has a constant connection to the manager interface. It could also be started from the script amportal. Think of ringall with autofill in a 120 channel PRI environment with callers and agents at about the same amount. Unfortunately asterisk tries to ring every agent at the same moment, generating a huge impact on the system at that moment. MOH stops for a few hundreds of seconds, etc. This is really not a FreePBX issue alone.
Second and most irrelevant suggestion: python might be better for scripting comparing its speed to php. If I had enough time, I’d be really willing to do it.