[OpenSIPS-Users] best way to do "foreach"

Liviu Chircu liviu at opensips.org
Wed May 12 10:43:07 EST 2021

On 12.05.2021 13:32, Kingsley Tart wrote:
> Is there a recommended way to implement a foreach loop with the
> iterator iterating over a list of known values?

Hey Kingsley,

There is actually a "foreach" statement available, applicable to any 
variable that can be indexed [1], so maybe you could write some cleaner 
code using that, depending on your available inputs.

As far as performance is concerned, the differences are negligible.  As 
long as you follow the rule of "$var is always faster than $avp", you 
should be writing nearly optimal script code.

Ultimately, the bottlenecks will forever be DNS queries, SQL queries, 
HTTP queries, TCP I/O, SIP retransmission timers, etc., with scripting 
technique being near the bottom of the optimization priority list...

[1]: https://www.opensips.org/Documentation/Script-Statements-3-2#toc4


Liviu Chircu
www.twitter.com/liviuchircu | www.opensips-solutions.com
OpenSIPS eBootcamp 2021 | www.opensips.org/training

More information about the Users mailing list