PHPackages                             estaheri/3x-ui - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. estaheri/3x-ui

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

estaheri/3x-ui
==============

An easy to use php library for MHSanaei/3x-ui

1.3(11mo ago)141.2k—2.7%2[1 PRs](https://github.com/es-taheri/3x-ui/pulls)MITPHP

Since Jul 2Pushed 3w ago4 watchersCompare

[ Source](https://github.com/es-taheri/3x-ui)[ Packagist](https://packagist.org/packages/estaheri/3x-ui)[ Docs](https://github.com/es-taheri/3x-ui)[ RSS](/packages/estaheri-3x-ui/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (3)Dependencies (2)Versions (4)Used By (0)

*💡 Tip: Use the filter headings menu (top-right) to jump between sections.*

An easy to use php library for [3x-ui](https://github.com/MHSanaei/3x-ui)
=========================================================================

[](#an-easy-to-use-php-library-for-3x-ui)

   ![3x-ui](./media/php_3x-ui.png)

[![Static Badge](https://camo.githubusercontent.com/7b21c72d289b5b42439ae58b5007b26591ee039a5507da094ce2e076c2931a85/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d76382e322d626c7565)](https://www.php.net/releases/8.2/en.php)[![Static Badge](https://camo.githubusercontent.com/aa3b9c63123bbdf56c7154c91111fcb64317e959cd0d5631cfa3ebcd268ee989/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f33782d2d75692d76322e342e382d253233303535363446)](https://github.com/MHSanaei/3x-ui/releases/tag/v2.4.8)[![Static Badge](https://camo.githubusercontent.com/e243f11282722a6d6db492592a626938969cbb841351b284c2ca6394bac5290b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f587261792d7632342e31312e32312d6461726b726564)](https://github.com/XTLS/Xray-core/releases/tag/v24.11.21)[![Total Downloads](https://camo.githubusercontent.com/d0c129cd50995dfd78c7785ef4ebb7d1b6d59029c1cb086af00618994ce3a0c6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f65737461686572692f33782d75692e737667)](https://github.com/es-taheri/3x-ui/releases/latest)[![Static Badge](https://camo.githubusercontent.com/72b9444938e97d39d5bfd15b730de49b93e3decbdfe9cc9487903b4db880db1d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d253233303037454336)](https://github.com/es-taheri/3x-ui/blob/master/LICENSE)

### PHP 3X-UI

[](#php-3x-ui)

**Simple open-source PHP library for managing MHSanaei 3x-ui panel without its official rest api.**

Important

This library is only for personal using, please do not use it for illegal purposes, please do not use it in a production environment.

Quick Start
-----------

[](#quick-start)

- Require library in your project 📁

```
composer require estaheri/3x-ui

```

- Require composer autoload in your php code ⚓

```
require_once __DIR__.'/vendor/autoload.php';
```

- Instantiating `Xui` class and set connection credentials 📡

```
$xui = new Xui($xui_host, $xui_port, $xui_path, $xui_ssl);
```

- Login to panel using username &amp; password 🔐

```
$xui->login($username, $password);
```

- Now you can do anything ✅

```
$xui->server; // Accessing to server methods (Status,Database,Stop/Restart Xray,...)
$xui->xray; // Accessing to xray methods (Inbounds,Outbounds,Routing,...)
$xui->panel; // Accessing to panel methods (Restart panel,Update/Get settings,...)
```

Full Documentation
------------------

[](#full-documentation)

[Responses](#responses)
[Protocols](#protocols)
[Rules](#rules)
[New Xui](#new-xui)

- [Login](#login)
- [Random](#random)
- [Uuid](#uuid)

[Xray](#xray)

- [Inbound](#inbound)
- [Outbound](#outbound)
- [Routing](#routing)
- [Reverse](#reverse)
- [Configs](#configs)

[Server](#server)

- [Status](#status)
- [Database](#database)
- [Xray-Restart-Stop](#xray-restart-stop)
- [Reality-Certificate](#reality-certificate)
- [Xui-log](#xui-log)

[Panel](#panel)

- [Settings](#settings)
- [Restart](#restart)
- [Default-Xray-Config](#default-xray-config)

### Responses

[](#responses)

All methods return value based this document :

- #### Methods Return

    [](#methods-return)

    We have 3 types of methods return value :
    - Object (Default)
    - JSON
    - Array

Note

You can set return type from `$output` property in all classes.
You can set it globally when Calling `Xui` Object-oriented class.

**General structure of recursive methods :**

```
$return = ['ok' => $ok, 'response' => $response, 'size' => $size, 'time_taken' => $time_taken]
#---------------------------------------------------------------------------------
$ok // Can be true/false based on request success or fail! (bool)
$response // response of request returned by panel (string|object|array)
$size // Size of response (int)
$time_taken // Request time taken in seconds (float)
```

- #### Response

    [](#response)

    We have 3 types of response in methods return value :

    - Object (Default)
    - JSON
    - Array

Note

You can set response type from `$response_output` property in all classes.
You can set it globally when Calling `Xui` Object-oriented class.

**General structure of response :**

```
$response = ['success' => $success, 'obj' => $obj, 'msg' => $msg]
#---------------------------------------------------------------------------------
$success // Can be true/false based on action success or fail! (bool)
$obj // data returned. (string|object|array)
$msg // Message for fail actions, Similar to error! (string)
```

### Protocols

[](#protocols)

You can create a config for inbound/outbound by calling its object-orinted class

Tip

All variables and properties of protocols and streams classes and methods based on Project X official documentations.
You can find full documentation of protocols and their configuration on [Xtls/Xray official website](https://xtls.github.io/en/)
[Inbound Protocols Docs](https://xtls.github.io/en/config/inbounds/)
[Outbound Protocols Docs](https://xtls.github.io/en/config/outbounds/)
[Inbound/Outbound Streams Docs](https://xtls.github.io/en/config/transport.html)

```
// Create Inbound config
use XUI\Xray\Inbound\Protocols\Vmess\Vmess;
$listen = '';
$port = 12345;
$config = new Vmess($listen, $port);
$config->settings->add_client($enable, $uuid, $email, $total_traffic, $expiry_time, $limit_ip, $tgid, $subid, $reset);
$config->stream_settings->ws_settings($accept_proxy_protocol,$path,$headers);
#---------------------------------------------------------------------------------
// Create Outbounds config
use XUI\Xray\Outbound\Protocols\Vmess\Vmess;
$config = new Vmess();
$config->settings->address = 'example.3xui.net';
$config->settings->port = 12345;
$config->settings->add_user($uuid, $security);
$config->stream_settings->ws_settings($accept_proxy_protocol, $path, $headers);
```

Supported Inbound protocols :

- Vmess
- Vless
- Trojan
- Shadowsocks
- Socks
- Http
- DokodomoDoor

Supported Outbound protocols :

- Vmess
- Vless
- Trojan
- Shadowsocks
- Socks
- Http
- Dns
- Blackhole
- Freedom

Supported Inbound/Outbound Streams and Security :

- tcp
- kcp
- ws
- http
- quic
- ds
- grpc
- sockopt
- tls
- reality

### Rules

[](#rules)

An object-oriented class for creating a routing rule

```
use XUI\Xray\Routing\Rule;
$rule = new Rule($inbound_tag,$outbound_tag);
// Or
$rule = Routing::rule($inbound_tag,$outbound_tag);
```

Get or Set a rule setting :

```
$rule->port($value); // return true on success and false on failure
$port = $rule->port();
```

Rule settings supported :

```
$rule->balancer_tag(); // Corresponds to the identifier of a balancer.
$rule->user(); // An array where each item represents an email address.
$rule->network(); // This can be "tcp", "udp", or "tcp,udp".
$rule->protocol(); // An array where each item represents a protocol. ["http" | "tls" | "bittorrent"]
$rule->domain_matcher(); // The domain matching algorithm used varies depending on the settings.
$rule->domain(); // The domain matching algorithm used varies depending on the settings.
$rule->ip(); // An array where each item represents an IP range.
$rule->port(); // The target port range
$rule->source(); // An array where each item represents an IP range in the format of IP, CIDR, GeoIP, or loading IP from a file.
$rule->source_port(); // The source port
$rule->attrs(); // A json object with string keys and values, used to detect the HTTP headers of the traffic.
$rule->type(); // Currently, only the option "field" is supported.
```

### New Xui

[](#new-xui)

Calling `Xui` Object-oriented class for creating connection to 3x-ui

```
$xui = new \XUI\Xui($host, $port, $uri_path, $has_ssl, $cookie_dir, $timeout, $proxy, $output, $response_output);
#---------------------------------------------------------------------------------
$host = 'localhost'; // Host address of 3x-ui panel. (Accepts Domain/Subdomain/Ipv4)
$port = 12345; // Port of 3x-ui panel. (1-65535)
$uri_path = '/'; // URI path of 3x-ui panel.
$has_ssl = false; // Does panel has SSL. (Default: FALSE)
$cookie_dir = __DIR__ . '/.cookie'; //
$timeout = 10; // HTTP Requests timeout
$proxy = null; // HTTP Requests proxy
$output = \XUI\Xui::OUTPUT_OBJECT; // Type of return value of methods. Use Xui::OUTPUT_xxx to set. (Accepts json,object,array)
$response_output = \XUI\Xui::OUTPUT_OBJECT; // Type of response value of requests. Use Xui::OUTPUT_xxx to set. (Accepts json,object,array)
```

- #### Login

    [](#login)

    After instantiating `Xui` class must use this method to login to panel.

Note

Library automatically use cookie if login recently

```
$xui->login($username,$password);
#---------------------------------------------------------------------------------
$username = 'admin'; // Settings login username
$password = 'xxxx'; // Settings login password
```

- #### Random

    [](#random)

    An static method for generating random string.

    ```
    \XUI\Xui::random($length);
    $length = 32; // Length of random string
    ```
- #### Uuid

    [](#uuid)

    An static method for generating random uuid useful to set inbound/outbounds clients uuid.

    ```
    \XUI\Xui::uuid();
    ```

### Xray

[](#xray)

A property to accessing Xray configs including Inbound,Outbound,Routing,Reverse,Others and restarting xray-core.

```
$xray = $xui->xray;
```

- #### Inbound

    [](#inbound)

    A property to accessing Xray configs **inbounds**.

    ```
    $inbound = $xray->inbound;
    ```

    ##### Methods

    [](#methods)

    ```
    # Add,Delete,Update,Get,Exist inbound
    $inbound->add($config, $remark, $total_traffic, $expiry_time, $download, $upload, $enable);
    $inbound->exist($inbound_id);
    $inbound->get($inbound_id);
    $inbound->update($inbound_id, $config, $remark, $total_traffic, $expiry_time, $download, $upload, $enable);
    $inbound->delete($inbound_id);
    # List,Online inbounds
    $inbound->onlines();
    $inbound->list();
    # Import,Export inbound
    $inbound->export($inbound_id);
    $inbound->import($exported_inbound);
    # Get,Clear client ips of inbound
    $inbound->get_client_ips($client_email);
    $inbound->clear_client_ips($client_email);
    $inbound->reset_client_traffic($inbound_id, $client_email);
    #---------------------------------------------------------------------------------
    $config = new \XUI\Xray\Inbound\Protocols\Vmess\Vmess(); // Configured protocol object oriented class
    $config->settings->add_client();
    $config->stream_settings->ws_settings(false, '/');
    $inbound_id = 123; // ID of inbound
    $remark = 'Me'; // Name of inbound
    $total_traffic = 100 * \XUI\Xui::UNIT_GIGABYTE; // Total traffic of inbound. (Unit: Byte)
    $download = 10 * \XUI\Xui::UNIT_GIGABYTE; // Download traffic usage of inbound. (Unit: Byte)
    $upload = 500 * \XUI\Xui::UNIT_MEGABYTE; // Upload traffic usage of inbound. (Unit: Byte)
    $enable = true; // Enable/Disable inbound
    $expiry_time = time() + (30 * 86400); // Expiry time of inbound. (Unit: unix timestamp in seconds)
    $exported_inbound = 'json'; // Json encoded exported inbound.
    $client_email = 'client1234@localhost'; // Client email on inbound
    ```
- #### Outbound

    [](#outbound)

    A property to accessing Xray configs **outbounds**.

    ```
    $outbound = $xray->outbound;
    ```

    ##### Methods

    [](#methods-1)

    ```
    # Add,Delete,Update,Get,Exist outbound
    $outbound->add($tag,$config,$proxy_settings,$send_through,$mux);
    $outbound->exist($outbound_tag);
    $outbound->get($outbound_tag);
    $outbound->update($outbound_tag, $tag, $config, $proxy_settings, $send_through, $mux);
    $outbound->delete($outbound_tag);
    # List outbound
    $outbound->list();
    #---------------------------------------------------------------------------------
    $config = new \XUI\Xray\Outbound\Protocols\Vmess\Vmess(); // Configured protocol object oriented class
    $config->settings->add_user(\XUI\Xui::uuid());
    $config->stream_settings->ws_settings(false);
    $tag = 'vmess-test'; // The identifier of this outbound connection
    $proxy_settings = null; // The outbound proxy configuration.
    $send_through = '0.0.0.0'; // The IP address used to send data.
    $mux = []; // Specific configuration related to Mux.
    $outbound_tag = 'vmess-test'; // The identifier of this outbound connection
    ```
- #### Routing

    [](#routing)

    A property to accessing Xray configs **routing**.

    ```
    $routing = $xray->routing;
    $loaded = $routing->load();
    if($loaded)
        echo "ok";
    else
        echo 'error';
    ```

Note

Before using routing methods must call `load()` method to load routing configs from xray config!

##### Methods

[](#methods-2)

```
# Set/Get routing domain strategy,domain matcher,balancers
$routing->domain_strategy();
$routing->domain_matcher();
$routing->balancers();
# Add,Delete,Update,Get,Exist routing rule
$routing->has_rule($rule_inbound_tag,$rule_outbound_tag);
$routing->add_rule($rule,$apply);
$routing->get_rule($rule_inbound_tag,$rule_outbound_tag);
$routing->update_rule($rule_inbound_tag,$rule_outbound_tag,$rule,$apply);
$routing->delete_rule($rule_inbound_tag,$rule_outbound_tag,$apply);
# Apply changes made to routing
$routing->update();
#---------------------------------------------------------------------------------
$rule_inbound_tag = ['inbound-12345','inbound-12346']; // An array where each item represents an identifier.
$rule_outbound_tag = 'direct'; // Corresponds to the identifier of an outbound.
$apply = true; // Apply changes to routing in xray config
$rule = \XUI\Xray\Routing\Routing::rule($inbound_tag,$outbound_tag); // Configured rule object oriented class
```

- #### Reverse

    [](#reverse)

    A property to accessing Xray configs **reverse**.

    ```
    $reverse = $xray->reverse;
    $loaded = $reverse->load();
    if($loaded)
        echo "ok";
    else
        echo 'error';
    ```

Note

Before using reverse methods must call `load()` method to load reverse configs from xray config!

##### Methods

[](#methods-3)

```
# Add,Delete,Update,Get,Exist reverse portal
$reverse->has_portal($portal_tag);
$reverse->add_portal($tag,$domain,$apply);
$reverse->get_portal($portal_tag);
$reverse->update_portal($portal_tag,$tag,$domain,$apply);
$reverse->delete_portal($portal_tag,$apply);
# Add,Delete,Update,Get,Exist reverse bridge
$reverse->has_bridge($bridge_tag);
$reverse->add_bridge($tag,$domain,$apply);
$reverse->get_bridge($bridge_tag);
$reverse->update_bridge($bridge_tag,$tag,$domain,$apply);
$reverse->delete_bridge($bridge_tag,$apply);
# Apply changes made to reverse
$reverse->update();
#---------------------------------------------------------------------------------
$portal_tag = 'portal-1'; // The identifier for the portal
$bridge_tag = 'bridge-1'; // The identifier for the bridge
$tag = 'portal-1'; // The identifier for the portal/bridge
$domain = 'reverse.xui'; // A domain name.
$apply = true; // Apply changes to reverse in xray config
```

- #### Configs

    [](#configs)

    Use these methods for configuring xray core or get xray core configuration.

Note

You must restart xray to apply changes made to xray configurations.
Use `set_config()` to apply default xray configuration got from `$xui->panel->default_xray_config()` Or set a full custom xray configuration.

##### Methods

[](#methods-4)

```
# Get full Xray configs
$xray->get_configs();
# Get/Update a Xray config/configs
$xray->get_config($config);
$xray->update_config($update);
# Set a full xray configuration
$xray->set_config($full_config);
# Restart xray core to apply changes made to xray config
$xray->restart();
# Get inbound tags
$xray->get_inbound_tags();
#---------------------------------------------------------------------------------
$config = 'log'; // Configuration/Configurations you want to get
$update = [
    'log' => [
        'access' => 'none',
        'dnsLog' => false,
        'error' => '',
        'loglevel' => 'warning',
        'maskAddress' => '',
    ]
]; // Configuration/Configurations you want to made to xray configs
$full_config = 'json'; // Json/object/array of xray full config
```

### Server

[](#server)

A property to accessing server status,panel database,restart/stop xray,xui logs,...

```
$server = $xui->server;
```

- #### Status

    [](#status)

    Use this method to get a full information about server resources and usage of it and information about xray-core. ```
    $server->status();
    ```
- #### Database

    [](#database)

    Import / Export panel SQLLite database. ```
    $server->get_db($path);
    $server->import_db($path_or_db);
    #---------------------------------------------------------------------------------
    $path = '/www/wwwroot/xui.example.com/x-ui.db'; // Path to .db file for exporting panel database
    $path_or_db = '/www/wwwroot/xui.example.com/x-ui.db'; // Path to .db file of exported panel database
    ```
- #### Xray-Restart-Stop

    [](#xray-restart-stop)

    Restart / Stop Xray-core ```
    $server->restart_xray();
    $server->stop_xray();
    ```
- #### Reality-Certificate

    [](#reality-certificate)

    Use this method to get a x25519 certificate for reality ```
    $server->get_x25519_cert();
    ```
- #### Xray-Full-Config

    [](#xray-full-config)

    Use this method to get xray-core fully config included inbounds,... ```
    $server->get_xray_config();
    ```
- #### Xui-log

    [](#xui-log)

    Get xui logs ```
    $server->get_xui_log($count, $level, $syslog);
    #---------------------------------------------------------------------------------
    $count = 10; // Count of logs
    $level = 'notice'; // Logs level (debug,info,notice,warning,error)
    $syslog = true; // Enable/Disable syslog output
    ```

### Panel

[](#panel)

A property to accessing panel settings,restart panel,default xray config.

- #### Settings

    [](#settings)

    Methods to get/update 3x-ui panel settings. ##### Methods

    [](#methods-5)

    ```
    # Get panel full settings
    $panel->settings();
    # Get a setting/ settings from panel settings
    $panel->get_setting($setting);
    # Update panel settings
    $panel->update_setting($update);
    #---------------------------------------------------------------------------------
    $setting = 'webPort'; // Specified setting you want to get
    $update = ['webPort'=>1234]; // Changes you want to made to Settings settings
    ```
- #### Restart

    [](#restart)

    Restart 3x-ui panel (Only panel!) ```
    $panel->restart();
    ```
- #### Default-Xray-Config

    [](#default-xray-config)

    Get default xray config based on panel and xray-core version. (Only Xray default config!) ```
    $panel->default_xray_config();
    ```

Special Thanks to
-----------------

[](#special-thanks-to)

- [MHSanaei](https://github.com/MHSanaei)
- [alireza0](https://github.com/alireza0/)

Support project
---------------

[](#support-project)

### Give Star ⭐

[](#give-star-)

**If this library is helpful to you, you may wish to give it a STAR**

### Donate 💵

[](#donate-)

**Help me improve this library by a donate** ❤️

- TRX : `TXFE1je6Ed7fADvxAQXXo2g45eQtXvwith`
- TON : `UQDb44qyae9n0hmgay3Bs_oom6RR8cZbLF5_9UCei0q13T0b`
- USDT (TRON): `TCTyFGJVkCgruAYmvPpetF6jVybuZSpTg6`
- USDT (TRX): `UQBnnLMdbAH6Pq86lsH9jEySH-D5___ctqUFKiuBXnd74FTD`

###  Health Score

42

—

FairBetter than 88% of packages

Maintenance76

Regular maintenance activity

Popularity27

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~192 days

Total

3

Last Release

347d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/51331257?v=4)[estaheri](/maintainers/estaheri)[@estaheri](https://github.com/estaheri)

---

Top Contributors

[![es-taheri](https://avatars.githubusercontent.com/u/70095105?v=4)](https://github.com/es-taheri "es-taheri (32 commits)")

---

Tags

хуйx-ui3x-ui3xui3x-ui php libraryx-ui php library

### Embed Badge

![Health badge](/badges/estaheri-3x-ui/health.svg)

```
[![Health](https://phpackages.com/badges/estaheri-3x-ui/health.svg)](https://phpackages.com/packages/estaheri-3x-ui)
```

###  Alternatives

[aws/aws-sdk-php

AWS SDK for PHP - Use Amazon Web Services in your PHP project

6.3k543.5M2.6k](/packages/aws-aws-sdk-php)[neuron-core/neuron-ai

The PHP Agentic Framework.

2.0k656.1k39](/packages/neuron-core-neuron-ai)[tencentcloud/tencentcloud-sdk-php

TencentCloudApi php sdk

3741.3M46](/packages/tencentcloud-tencentcloud-sdk-php)[civicrm/civicrm-core

Open source constituent relationship management for non-profits, NGOs and advocacy organizations.

751291.4k43](/packages/civicrm-civicrm-core)[spatie/laravel-export

Create a static site bundle from a Laravel app

674146.0k6](/packages/spatie-laravel-export)[oat-sa/tao-core

TAO core extension

66143.7k124](/packages/oat-sa-tao-core)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
