> 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="https://3704471835-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPK4TuzRBnP7rt8htho-887967055%2Fuploads%2FVwCHOf6WE37tuR2QBnX2%2FCustomFileMenu.png?alt=media&amp;token=8d68d5ed-1632-4ae4-b393-c82f7daf487a" alt=""><figcaption><p>Раздел "Кастомизация системных файлов"</p></figcaption></figure>

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

<figure><img src="https://3704471835-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPK4TuzRBnP7rt8htho-887967055%2Fuploads%2Fs8dhNaf2xpdru73vq1BA%2FmodulesConf.png?alt=media&amp;token=ec6bd2e0-2d1a-4a5a-b49e-b3c693890ab8" alt=""><figcaption><p>Файл Modules.conf</p></figcaption></figure>

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

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

<figure><img src="https://3704471835-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPK4TuzRBnP7rt8htho-887967055%2Fuploads%2Fgit-blob-3ecf2f70c0ca03c307d03558e5b3311c415c8ceb%2FcodeForModulesConf%20(1).png?alt=media" alt=""><figcaption><p>Код для файла Modules.conf</p></figcaption></figure>

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

<figure><img src="https://3704471835-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPK4TuzRBnP7rt8htho-887967055%2Fuploads%2Fgit-blob-b24a5272bf542c60298cb79940a68b03a9c7c6a1%2FcodeForExtensionsConf%20(2).png?alt=media" 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="https://3704471835-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPK4TuzRBnP7rt8htho-887967055%2Fuploads%2F87Yi9dlXFn6L7hvogaUD%2FcodeForExtensionsConf2.png?alt=media&amp;token=fcf117d0-910b-467e-9eb4-50b75310949c" 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
