> For the complete documentation index, see [llms.txt](https://docs.mikopbx.com/mikopbx/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.mikopbx.com/mikopbx/faq/outbound-routing/number-templates/uniform-distribution-of-outgoing.md).

# Равномерное распределение исходящих

1. Перейдите в раздел [Кастомизация системных файлов](/mikopbx/manual/system/custom-files.md)

<figure><img src="/files/9QWBoYXitdDpNsJvwYtL" alt=""><figcaption><p>Раздел "Кастомизация системных файлов"</p></figcaption></figure>

2. Откройте на редактирование **modules.conf**

<figure><img src="/files/GQiq3WOyViHhrCpGdlky" alt=""><figcaption><p>Файл Modules.conf</p></figcaption></figure>

3. Добавьте следующий код в конец файла:

```php
load => func_global.so
```

<figure><img src="/files/N0mDqW3muN6AkmJDKKTN" alt=""><figcaption><p>Код для файла Modules.conf</p></figcaption></figure>

4. Откройте на редактирование файл **extensions.conf**

<figure><img src="/files/KJJdvMokAVCFT6UPbBqg" alt=""><figcaption><p>Файл Extensions.conf</p></figcaption></figure>

5. Добавьте следующий код в конец файла:

{% code fullWidth="false" %}

```php
[all-outgoing-custom]
exten => _X!,1,NoOp()
    same => n,Set(NEED_RETURN=0)
    ; Описываем список провайдеров
    same => n,Set(PUSH(rrItem)=SIP-1601534775)
    same => n,Set(PUSH(rrItem)=SIP-1611151795)    
    same => n,Set(PUSH(rrItem)=SIP-1681205343)
    ; Максимальное количество одновременных звонков через линию
    same => n,Set(busyLevel=50)
    
    ; Проверка, есть ли провайдер в списке. 
    same => n,ExecIf($[ "${FIELDNUM(rrItem,\,,${PROVIDER_ID})}" == "0" ]?return)
    ; Если ID приоритетного провайдера определен, то сразу к проверке. 
    same => n,GotoIf($[ "${rrElement}x" != "x" ]?check)
    ; Инициализация массива
    same => n,Set(rrArray=${EMPTY})
    same => n,Set(i=${SHIFT(rrItem)})
    same => n,While(1)
    same => n,ExecIf($[ "${i}x" == "x" ]?ExitWhile())
    same => n,ExecIf($[ "${rrArray}x" != "x" ]?Set(rrArray=${rrArray},))
    same => n,ExecIf($[ "${GLOBAL(${i})}x" == "x" ]?Set(GLOBAL(${i})=0))
    same => n,Set(rrArray=${rrArray}${i}:${GLOBAL(${i})})
    same => n,Set(i=${SHIFT(rrItem)})
    same => n,EndWhile
    ; Поиск элемента с меньшим весом
    same => n,Set(rrArray=${SORT(${rrArray})})
    same => n,Set(rrElement=${SHIFT(rrArray)})
    same => n,While(1)
    same => n,ExecIf($[ $[${GROUP_COUNT(${rrElement})} < ${busyLevel}] ]?ExitWhile())
    same => n,ExecIf($[ "${rrElement}x" == "x" ]?ExitWhile())
    same => n,NoOp( ${rrElement} - is busy)
    same => n,Set(rrElement=${SHIFT(rrArray)})
    same => n,EndWhile
    same => n,NoOp(--- ${rrElement} ---)
    
    ; Проверка совпадает ли провайдер
    same => n(check),ExecIf($[ "${PROVIDER_ID}x" != "${rrElement}x" ]?Set(NEED_RETURN=1))
    same => n,ExecIf($[ "${PROVIDER_ID}x" != "${rrElement}x" ]?return)
    ; Увеличиваем счетчик
    same => n,Set(GLOBAL(${rrElement})=$[${GLOBAL(${rrElement})} + 1])
    ; Счетчик активных звонков через провайдера
    same => n,Set(GROUP()=${rrElement})
    same => n,return
```

{% endcode %}

<figure><img src="/files/HhwEjJXOtcyLtcJbxBwb" alt=""><figcaption><p>Код для extensions.conf</p></figcaption></figure>

{% hint style="info" %}
В строках вида «**Set(PUSH(rrItem)=SIP-1601534775)**» перечисляются идентификаторы провайдеров, среди которых следует равномерно распределять исходящие. Идентификатор можно скопировать в адресной строке браузера при редактировании провайдера.\
В переменной «**busyLevel**» определяется максимально допустимое количество одновременных звонков через провайдера.
{% endhint %}

{% hint style="warning" %}
Для каждого провайдера потребуется описать исходящий маршрут. Шаблон в маршрутах должен быть одинаковым.
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.mikopbx.com/mikopbx/faq/outbound-routing/number-templates/uniform-distribution-of-outgoing.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
