OpenResty Edge™ PHP SDK 手册
All of these methods will throw an exception if the client encounters errors, for example, network error, 400 and 500 level errors.
| Method | Parameters | Parameters type | Description | Return type | 
|---|---|---|---|---|
| Edge2Client | $opts | array | init SDK client | object | 
| login | login to edge system | bool | ||
| useApp | $appID | number | set the application you want to operate | bool | 
| newApp | $opts | array | add a new application | number | 
| updateApp | $opts | array | update application | bool | 
| getApp | get info of application | array | ||
| getAllApps | $detail | bool | get info of all applications | array | 
| appendAppDomain | $opts | array | append one more domain of application | bool | 
| deleteApp | $appID | number | delete application | bool | 
| searchApp | $opts | array | search application | array | 
| newUpstream | $opts | array | add a new upstream | number | 
| updateUpstream | $opts | array | update upstream | bool | 
| deleteUpstream | $UpstreamID | number | delete upstream | bool | 
| newRewriteRule | $opts | array | add a new rewrite rule | number | 
| updateRewriteRule | $opts | array | update rewrite rule | bool | 
| getRewriteRule | rule_id | number | get request rewrite rule | array | 
| getAllRewriteRules | app_id | number | get all rewrite rules | array | 
| deleteRewriteRule | $RewriteRuleID | number | delete rewrite rule | bool | 
| newAppDymetrics | $opts | array | new application dynamic metrics | array | 
| deleteAppDymetrics | $metricID | number | delete application dynamic metrics | bool | 
| getAppDymetrics | get application dynamic metrics | bool | ||
| getAppDymetricsData | $opts | array | get dynamic metrics data | array | 
| newAppIPList | $opts | array | create a new application IP list | number | 
| deleteAppIPList | $appIPListID | number | delete application IP list by id | bool | 
| updateAppIPList | $opts | array | update application IP list by id | bool | 
| appendToAppIPList | $opts | array | append IP to application IP list by id | bool | 
| removeFromAppIPList | $opts | array | remove IP from application IP list by id | bool | 
| getAppIPList | $appIPListID | number | get application IP list by id | array | 
| getAllAppIPList | get all AppIP list | array | ||
| setCertKey | $opts | array | set SSL key and cert | number | 
| updateCertKey | $opts | array | update SSL key and cert | bool | 
| getCertKey | $opts | array | get SSL key and cert by cert id | array | 
| getAllCertKeys | $opts | array | get all SSL keys and certs | array | 
| deleteCertKey | $certID | number | delete cert | bool | 
| setGlobalCertKey | $opts | array | set global SSL key and cert | number | 
| updateGlobalCertKey | $opts | array | update global SSL key and cert | bool | 
| getGlobalCertKey | $certID | number | get global SSL key and cert by cert id | array | 
| getAllGlobalCertKeys | get all SSL keys and certs | array | ||
| deleteGlobalCertKey | $certID | number | delete global cert | bool | 
| newCachePurgeTask | $opts | array | add cache purge task | number | 
| getCachePurgeTask | $taskID | number | get cache purge task | array | 
| getAllCachePurgeTasks | get all cache purge tasks | array | ||
| deleteCachePurgeTask | $taskID | number | delete cache purge task | bool | 
| newEL | $opts | array | add EL code | bool | 
| newRelease | new release | bool | ||
| pendingChanges | pending changes | number | ||
| getGlobalConfig | $opts | array | get global config | json format string | 
| setWorker | $opts | array | set global config of worker | bool | 
| setSSL | $opts | array | set global config of SSL | bool | 
| setProxy | $opts | array | set global config of proxy | bool | 
| setClientReq | $opts | array | set global config of client request | bool | 
| setFileBuffer | $opts | array | set global config of client buffer | bool | 
| setLog | $opts | array | set global config of log | bool | 
| setDNS | $opts | array | set global config of DNS | bool | 
| setGzip | $opts | array | set global config of Gzip | bool | 
| newDNS | $opts | array | add a new DNS | number | 
| updateDNS | $opts | array | update DNS | bool | 
| deleteDNS | $dnsID | number | delete DNS | bool | 
| newDnsRecord | $opts | array | add record of DNS | bool | 
| updateDnsRecord | $opts | array | update record of DNS | bool | 
| deleteDnsRecord | $opts | array | delete record of DNS | bool | 
| disabledDnsRecord | $opts | array | disabled record of DNS | bool | 
| newGlobalDymetrics | $opts | array | new global dynamic metrics | array | 
| deleteGlobalDymetrics | $metricID | number | delete global dynamic metrics | bool | 
| getGlobalDymetrics | get global dynamic metrics | bool | ||
| getGlobalDymetricsData | $opts | array | get dynamic metrics data | array | 
| getMetricData | $appID | number | get last one minute metric data of app | array | 
| newLayerPolicy | $opts | array | add a layer policy | number | 
| deleteLayerPolicy | $policyID | number | delete a layer policy | bool | 
| updateLayerPolicy | $opts | array | update a layer policy | bool | 
| getLayerPolicies | get all layer policies | array | ||
| newGlobalIPList | $opts | array | create a new global IP list | number | 
| deleteGlobalIPList | $globalIPListID | number | delete global IP list by id | bool | 
| updateGlobalIPList | $opts | array | update global IP list by id | bool | 
| appendToGlobalIPList | $opts | array | append IP to global IP list by id | bool | 
| removeFromGlobalIPList | $opts | array | remove IP from global IP list by id | bool | 
| getGlobalIPList | $globalIPListID | number | get global IP list by id | array | 
| getAllGlobalIPList | get all global IP list | array | ||
| convCrlToLuaModule | $crl_files | array | convert CRL files into Lua Module | string | 
Edge2Client
$client = Edge2Client($opts)
Description of array $opts:
| Key name | Type | Required | Description | 
|---|---|---|---|
| edge_admin_addr | string | yes | address of edge admin, including host and port | 
| username | string | no | username of edge-admin, required when api_token is empty | 
| password | string | no | password of edge-admin, required when api_token is empty | 
| api_token | string | no | api_token, required when username and password are empty | 
Example:
<?php
require_once(__DIR__ . '/vendor/autoload.php');
use OpenResty\Edge2Client;
// use username and password
$client = new Edge2Client([
   'edge_admin_addr' => 'https://admin.openresty.com',
   'username' => 'admin',
   'password' => '123456'
]);
// use api token
$client = new Edge2Client([
   'edge_admin_addr' => 'https://admin.openresty.com',
   'api_token' => 'xxx-xxx-xxx-xxx'
]);
?>
login
$ok = login()
Returns true if login success else false.
Example:
<?php
require_once(__DIR__ . '/vendor/autoload.php');
use OpenResty\Edge2Client;
$client = new Edge2Client([
   'edge_admin_addr' => 'https://admin.openresty.com',
   'username' => 'admin',
   'password' => '123456'
]);
$ok = $client->login();
?>
useApp
$ok = useApp($appID)
Returns true if success else false.
Example:
<?php
require_once(__DIR__ . '/vendor/autoload.php');
use OpenResty\Edge2Client;
$client = new Edge2Client([
   'edge_admin_addr' => 'https://admin.openresty.com',
   'username' => 'admin',
   'password' => '123456'
]);
$ok = $client->login();
$ok = $client->useApp(10);
?>
newApp
$appID = newApp($opts)
Description of array $opts:
| Key name | Type | Required | Description | 
|---|---|---|---|
| domains | array | yes | domains of application | 
| label | string | yes | name of application | 
Example:
<?php
require_once(__DIR__ . '/vendor/autoload.php');
use OpenResty\Edge2Client;
$client = new Edge2Client([
   'edge_admin_addr' => 'https://admin.openresty.com',
   'username' => 'admin',
   'password' => '123456'
]);
$ok = $client->login();
$appID = $client->newApp([
   'domains' => ['orig.foo.com'],
   'label' => 'origin site for foo.com',
]);
?>
appendAppDomain
$ok = appendAppDomain($opts);
Description of array $opts:
| Key name | Type | Required | Description | 
|---|---|---|---|
| appID | int | no | id of application, default is current application’s id | 
| domain | array | yes | domain of application | 
| isWildcard | bool | no | default is false | 
Example:
<?php
require_once(__DIR__ . '/vendor/autoload.php');
use OpenResty\Edge2Client;
$client = new Edge2Client([
   'edge_admin_addr' => 'https://admin.openresty.com',
   'username' => 'admin',
   'password' => '123456'
]);
$ok = $client->login();
$appID = $client->newApp([
   'domains' => ['orig.foo.com'],
   'label' => 'origin site for foo.com',
]);
$client->appendAppDomain(['domain' => 'foo.test.com']);
?>
updateApp
$ok = updateApp($opts);
Description of array $opts:
| Key name | Type | Required | Description | 
|---|---|---|---|
| domains | array | yes | domains of application | 
| label | string | yes | name of application | 
Example:
<?php
require_once(__DIR__ . '/vendor/autoload.php');
use OpenResty\Edge2Client;
$client = new Edge2Client([
   'edge_admin_addr' => 'https://admin.openresty.com',
   'username' => 'admin',
   'password' => '123456'
]);
$ok = $client->login();
$appID = $client->newApp([
   'domains' => ['orig.foo.com'],
   'label' => 'origin site for foo.com',
]);
$appID = $client->updateApp([
   'domains' => ['orig.foo.com'],
   'label' => 'origin site for foo.com'
]);
?>
getApp
$ok = getApp($appID);
Example:
<?php
require_once(__DIR__ . '/vendor/autoload.php');
use OpenResty\Edge2Client;
$client = new Edge2Client([
   'edge_admin_addr' => 'https://admin.openresty.com',
   'username' => 'admin',
   'password' => '123456'
]);
$ok = $client->login();
$appID = $client->newApp([
   'domains' => ['orig.foo.com'],
   'label' => 'origin site for foo.com',
]);
$app_info = $client->getApp();
?>
getAllApps
$ok = getAllApps($detail);
| Key name | Type | Required | Description | 
|---|---|---|---|
| detail | bool | no | default is false, only return id of apps. | 
Example:
<?php
require_once(__DIR__ . '/vendor/autoload.php');
use OpenResty\Edge2Client;
$client = new Edge2Client([
   'edge_admin_addr' => 'https://admin.openresty.com',
   'username' => 'admin',
   'password' => '123456'
]);
$ok = $client->login();
$appID = $client->newApp([
   'domains' => ['orig.foo.com'],
   'label' => 'origin site for foo.com',
]);
$apps_info = $client->getAllApps();
?>
deleteApp
$ok = deleteApp($appID);
Example:
<?php
require_once(__DIR__ . '/vendor/autoload.php');
use OpenResty\Edge2Client;
$client = new Edge2Client([
   'edge_admin_addr' => 'https://admin.openresty.com',
   'username' => 'admin',
   'password' => '123456'
]);
$ok = $client->login();
$appID = $client->newApp([
   'domains' => ['orig.foo.com'],
   'label' => 'origin site for foo.com',
]);
$ok = $client->deleteApp($appID);
?>
searchApp
$ok = searchApp($opts);
Description of array $opts:
| Key name | Type | Required | Description | 
|---|---|---|---|
| appDomain | string | no | the search keyword of app domain, support the regular expressions | 
| upstreamIp | string | no | ip address of app’s upstream | 
Example:
<?php
require_once(__DIR__ . '/vendor/autoload.php');
use OpenResty\Edge2Client;
$client = new Edge2Client([
   'edge_admin_addr' => 'https://admin.openresty.com',
   'username' => 'admin',
   'password' => '123456'
]);
$ok = $client->login();
$app_info = $client->client->searchApp(['appDomain' => 'test']);
$app_id = $app_info[0]['id'];
?>
newUpstream
$appID = newUpstream($opts)
Description of array $opts:
| Key name | Type | Required | Description | 
|---|---|---|---|
| name | string | yes | name of upstream | 
| servers | array | yes | upstreams | 
| ssl | bool | no | set protocol to HTTPS, default is false(HTTP) | 
| health_check | bool | no | enable active health check, default is false | 
servers
Description of array servers in $opts:
| Key name | Type | Required | Description | 
|---|---|---|---|
| ip | string | yes | ip of upstream | 
| port | string | yes | port of upstream | 
| weight | number | no | weight of upstream, default is 1 | 
| status | number | no | enabled or disabled upstream, default is 1 (enabled) | 
| health_checker | dict | no | detail configure of health checker, default is none | 
Example:
<?php
require_once(__DIR__ . '/vendor/autoload.php');
use OpenResty\Edge2Client;
$client = new Edge2Client([
   'edge_admin_addr' => 'https://admin.openresty.com',
   'username' => 'admin',
   'password' => '123456'
]);
$ok = $client->login();
$appID = $client->newApp([
   'domains' => ['orig.foo.com'],
   'label' => 'origin site for foo.com',
]);
$upstreamID = $client->newUpstream([
   'name' => 'origin-upstream',
   'servers' => [
        ['ip' => '172.22.31.1','port' => 80],
        ['ip' => '172.22.31.2','port' => 80,'weight' => 2]
    ]
]);
updateUpstream
$ok = updateUpstream($opts)
Description of array $opts:
| Key name | Type | Required | Description | 
|---|---|---|---|
| up_id | number | yes | id of rule | 
| name | string | yes | name of upstream | 
| servers | array | yes | upstreams | 
| ssl | bool | no | set protocol to HTTPS, default is false(HTTP) | 
| health_check | bool | no | enable active health check, default is false | 
servers
Description of array servers in $opts:
| Key name | Type | Required | Description | 
|---|---|---|---|
| ip | string | yes | ip of upstream | 
| port | string | yes | port of upstream | 
| weight | number | no | weight of upstream, default is 1 | 
| disabled | number | no | disabled upstream, default is 0 | 
Example:
<?php
require_once(__DIR__ . '/vendor/autoload.php');
use OpenResty\Edge2Client;
$client = new Edge2Client([
   'edge_admin_addr' => 'https://admin.openresty.com',
   'username' => 'admin',
   'password' => '123456'
]);
$ok = $client->login();
$appID = $client->newApp([
   'domains' => ['orig.foo.com'],
   'label' => 'origin site for foo.com',
]);
$upstreamID = $client->newUpstream([
   'name' => 'origin-upstream',
   'servers' => [
            ['ip' => '172.22.31.1', 'port' => 80],
            ['ip' => '172.22.31.2', 'port' => 80, 'weight' => 2]
        ]
]);
$ok = $client->updateUpstream([
        'up_id' => $upstreamID,
        'name' => 'backup-upstream',
        'servers' => [
                ['domain' => 'test.com', 'port' => 8080, 'weight' => 3],
                ['ip' => '172.22.31.6', 'port' => 80]
        ],
        'health_checker' => [
            'type' => 'http',
            'http_req_uri' => '/status',
            'http_req_host' => 'test.com',
            'interval' => 3,
            'interval_unit' => 'sec',
            'timeout' => 1,
            'fall' => 3,
            'rise' => 2,
            'valid_statuses' => [200, 302],
            'report_interval' => 3,
            'report_interval_unit' => 'min'
        ]
    ]);
deleteUpstream
$ok = deleteUpstream($up_id);
Example:
<?php
require_once(__DIR__ . '/vendor/autoload.php');
use OpenResty\Edge2Client;
$client = new Edge2Client([
   'edge_admin_addr' => 'https://admin.openresty.com',
   'username' => 'admin',
   'password' => '123456'
]);
$ok = $client->login();
$appID = $client->newApp([
   'domains' => ['orig.foo.com'],
   'label' => 'origin site for foo.com',
]);
$upstreamID = $client->newUpstream([
   'name' => 'origin-upstream',
   'servers' => [
            ['ip' => '172.22.31.1','port' => 80],
            ['ip' => '172.22.31.2','port' => 80, 'weight' => 2]
        ]
]);
$ok = $client->deleteUpstream($upstreamID);
?>
newProxyRule
$ruleID = newProxyRule($opts)
Description of array $opts:
| Key name | Type | Required | Description | 
|---|---|---|---|
| upstreams | array | yes | upstreams | 
| backupUpstreams | array | yes | backup upstreams | 
| timeout | number | no | timeout of proxy, default is 3 seconds | 
| connectTimeout | number | no | connect timeout of proxy, default is the same as timeout | 
| readTimeout | number | no | read timeout of proxy, default is the same as timeout | 
| sendTimeout | number | no | send timeout of proxy, default is the same as timeout | 
upstreams
Description of array upstreams in $opts:
| Key name | Type | Required | Description | 
|---|---|---|---|
| upstream | number | yes | id of upstream | 
| weight | number | no | weight of upstream, default is 1 | 
Example:
<?php
require_once(__DIR__ . '/vendor/autoload.php');
use OpenResty\Edge2Client;
$client = new Edge2Client([
   'edge_admin_addr' => 'https://admin.openresty.com',
   'username' => 'admin',
   'password' => '123456'
]);
$ok = $client->login();
$appID = $client->newApp([
   'domains' => ['orig.foo.com'],
   'label' => 'origin site for foo.com',
]);
$upstreamID = $client->newUpstream([
   'name' => 'origin-upstream',
   'servers' => [
            ['ip' => '172.22.31.1', 'port' => 80],
            ['ip' => '172.22.31.2', 'port' => 80, 'weight' => 2]
        ]
]);
$backupUpstreamID = $client->newUpstream([
   'name' => 'backup-upstream',
   'servers' => [
        ['ip' => '172.22.31.3', 'port' => 8000],
        ['ip' => '172.22.31.4', 'port' => 80, 'weight' => 3]
        ]
]);
$proxyRuleID = $client->newProxyRule([
   'upstreams' => [['upstream' => $upstreamID, 'weight' => 2]],
   'backup_upstreams' => [['upstream' => $backupUpstreamID]]
]);
?>
newRewriteRule
$rewriteRuleID = newRewriteRule($opts)
Description of array $opts:
| Key name | Type | Required | Description | 
|---|---|---|---|
| condition | list | no | conditions of rule | 
| conseq | dict or list | no | actions of rule | 
| waf | list | no | rules of waf | 
| proxy | list | no | rules of proxy | 
| cache | list | no | rules of cache | 
| content | list | no | rules of content | 
condition
Description of array condition in $opts:
| Key name | Type | Required | Description | 
|---|---|---|---|
| var | string or array | yes | name of edgelang builtin predicate function if type is string, name and args of function if type isarray | 
| op | string | no | operator, default is eq | 
| val | string | either valorvals | value | 
| vals | array | either valorvals | array of val | 
conseq
Description of array conseq in $opts:
| Key name | Type | Required | Description | 
|---|---|---|---|
| edgelang builtin action function | string | yes | one of edgelang builtin action functions | 
| args of edgelang builtin action function | array | yes | args of edgelang builtin action function | 
Example:
<?php
require_once(__DIR__ . '/vendor/autoload.php');
use OpenResty\Edge2Client;
$client = new Edge2Client([
   'edge_admin_addr' => 'https://admin.openresty.com',
   'username' => 'admin',
   'password' => '123456'
]);
$ok = $client->login();
$appID = $client->newApp([
   'domains' => ['orig.foo.com'],
   'label' => 'origin site for foo.com',
]);
$condition = [
    ['var' => 'host', 'op' => 'eq', 'val' => "con.foo.com"],
    ['var' => ['req-header', 'Referer'], 'vals' => [['foo\d+','rx'], 'foo.com']]
];
$conseq = [
    'print' => ['msg' => 'hello'],
    enable-'websocket' => [],
   'redirect' => ['url' => '/cn/2017/', 'code' => 302]
];
$rewriteRuleID = $client->newRewriteRule([
   'condition' => $condition,
   'conseq' => $conseq
]);
?>
waf
Description of array waf:
| Key name | Type | Required | Description | 
|---|---|---|---|
| rule_sets | list | no | the set of user defined rules in global waf, default is empty array | 
| scanner_detection | bool | no | whether to enable this type of detection, default is False | 
| protocol_enforcement | bool | no | whether to enable this type of detection, default is False | 
| protocol_attack | bool | no | whether to enable this type of detection, default is False | 
| application_attack_lfi | bool | no | whether to enable this type of detection, default is False | 
| application_attack_rfi | bool | no | whether to enable this type of detection, default is False | 
| application_attack_rce | bool | no | whether to enable this type of detection, default is False | 
| application_attack_php | bool | no | whether to enable this type of detection, default is False | 
| application_attack_nodejs | bool | no | whether to enable this type of detection, default is False | 
| application_attack_xss | bool | no | whether to enable this type of detection, default is False | 
| application_attack_sqli | bool | no | whether to enable this type of detection, default is False | 
| application_attack_session_fixation | bool | no | whether to enable this type of detection, default is False | 
| application_attack_java | bool | no | whether to enable this type of detection, default is False | 
| action | string | yes | one of log,403 Forbidden,edge-captcha,redirect | 
| threshold | string | yes | one of high,mediumorlow | 
| clearance | number | no | clearance time of edge captcha challenge, default is 60 secs | 
| redirect_url | string | no | redirect url when actionisredirect | 
Example: of waf rule
<?php
require_once(__DIR__ . '/vendor/autoload.php');
use OpenResty\Edge2Client;
$client = new Edge2Client([
   'edge_admin_addr' => 'https://admin.openresty.com',
   'username' => 'admin',
   'password' => '123456'
]);
$ok = $client->login();
$appID = $client->newApp([
   'domains' => ['orig.foo.com'],
   'label' => 'origin site for foo.com',
]);
$condition = [['var' => 'uri', 'op' => 'prefix', 'val' => "/foo"]];
$waf = ['robots' => true, 'generic' => true, 'inject' => true,
        'action' => '403 Forbidden', 'threshold' => 'high'];
$rewrite_waf_rule_id = $client->newRewriteRule(['waf' => $waf, 'condition' => $condition]);
?>
proxy
Description of array proxy:
| Key name | Type | Required | Description | 
|---|---|---|---|
| upstreams | list | yes | upstreams | 
| backup_upstreams | list | yes | backup upstreams | 
| timeout | number | no | timeout of proxy, default is 3 seconds | 
| connect_timeout | number | no | connect timeout of proxy, default is the same as timeout | 
| read_timeout | number | no | read timeout of proxy, default is the same as timeout | 
| send_timeout | number | no | send timeout of proxy, default is the same as timeout | 
| retries | number | no | retries time, default is 1 | 
| retry_condition | list | no | conditions of retry, default is [“error”, “timeout”, “invalid_header”, “http_500”, “http_502”, “http_504”]. And “http_503”, “http_403”, “http_404”, “http_429” and “non_valueempotent”(means even when method is POST, LOCK, PATCH) are also optional. | 
| balancer_algorithm | string | no | algorithm of balancing policy, default is roundrobin, and you can set tohashandchash. | 
| balancer_vars | list | no | variables of balancing policy. If you set to balancer_algorithm to hashorchash, then you must set balancer_vars too. | 
upstreams
Description of array upstreams and backup_upstreams:
| Key name | Type | Required | Description | 
|---|---|---|---|
| upstream | number | yes | id of upstream | 
| weight | number | no | weight of upstream, default is 1 | 
Example:
<?php
require_once(__DIR__ . '/vendor/autoload.php');
use OpenResty\Edge2Client;
$client = new Edge2Client([
   'edge_admin_addr' => 'https://admin.openresty.com',
   'username' => 'admin',
   'password' => '123456'
]);
$ok = $client->login();
$appID = $client->newApp([
   'domains' => ['orig.foo.com'],
   'label' => 'origin site for foo.com',
]);
$upstream_id = $client->newUpstream([
                        'name' => 'origin-upstream',
                        'servers' => [
                                ['ip' => '172.22.31.1', 'port' => 80],
                                ['ip' => '172.22.31.2', 'port' => 80, 'weight' => 2]
                            ]
                        ]);
$backup_upstream_id = $client->newUpstream([
                              'name' => 'backup-upstream',
                              'servers' => [
                                    ['ip' => '172.22.31.3', 'port' => 8000],
                                    ['ip' => '172.22.31.4', 'port' => 80, 'weight' => 3]
                                 ]
                            ]);
$ok = $client->updateUpstream([
                        'up_id' => $backup_upstream_id,
                        'name' => 'backup-upstream',
                        'servers' => [
                                ['ip' => '172.22.31.5', 'port' => 80, 'weight' => 3],
                                ['ip' => '172.22.31.6', 'port' => 80]
                            ]
                        ]);
$proxy = [
            'upstreams' => [['upstream' => $upstream_id, 'weight' => 2]],
            'backup_upstreams' => [['upstream' => $backup_upstream_id]]
        ];
$proxy_rule_id = $client->newRewriteRule(['proxy' => $proxy]);
?>
cache
Description of array cache:
| Key name | Type | Required | Description | 
|---|---|---|---|
| cache_key | list | yes | cache keys | 
Example:
<?php
require_once(__DIR__ . '/vendor/autoload.php');
use OpenResty\Edge2Client;
$client = new Edge2Client([
   'edge_admin_addr' => 'https://admin.openresty.com',
   'username' => 'admin',
   'password' => '123456'
]);
$ok = $client->login();
$appID = $client->newApp([
   'domains' => ['orig.foo.com'],
   'label' => 'origin site for foo.com',
]);
$condition = [['var' => 'client-country', 'op' => 'eq', 'val' => 'CN']];
$cache_key = ['uri', 'query-string', 'client-city'];
$cache_rule = ['cache_key' => $cache_key, 'cluster_hash' => true ];
$cache_rule_id = $client->newRewriteRule(['cache' => $cache_rule, 'condition' => $condition]);
?>
content
Description of array content:
| Key name | Type | Required | Description | 
|---|---|---|---|
| favicon | number | yes | file id | 
Example:
<?php
require_once(__DIR__ . '/vendor/autoload.php');
use OpenResty\Edge2Client;
$client = new Edge2Client([
   'edge_admin_addr' => 'https://admin.openresty.com',
   'username' => 'admin',
   'password' => '123456'
]);
$ok = $client->login();
$appID = $client->newApp([
   'domains' => ['orig.foo.com'],
   'label' => 'origin site for foo.com',
]);
$condition = [
            ['var' => 'uri', 'op' => 'prefix', 'val' => '/foo']
        ];
$file_id = $client->uploadFavicon($name = 'test', $faviconContent = content);
$rule_id = $client->newRewriteRule(['condition' => $condition, 'content' => ['favicon' => $file_id]]);
?>
updateRewriteRule
$ok = updateRewriteRule($opts)
Description of array $opts:
| Key name | Type | Required | Description | 
|---|---|---|---|
| ruleID | number | yes | conditions of rule | 
| condition | array | no | conditions of rule | 
| conseq | array | yes | actions of rule | 
Example:
<?php
require_once(__DIR__ . '/vendor/autoload.php');
use OpenResty\Edge2Client;
$client = new Edge2Client([
   'edge_admin_addr' => 'https://admin.openresty.com',
   'username' => 'admin',
   'password' => '123456'
]);
$ok = $client->login();
$appID = $client->newApp([
   'domains' => ['orig.foo.com'],
   'label' => 'origin site for foo.com',
]);
$condition = [
    ['var' => 'host', 'op' => 'eq', 'val' => "con.foo.com"],
    ['var' => ['req-header', 'Referer'], 'vals' => [['foo\d+','rx'], 'foo.com']]
];
$conseq = [
    'print' => ['msg' => 'hello'],
    enable-'websocket' => [],
    'redirect' => ['url' => '/cn/2017/', 'code' => 302]
];
$rewriteRuleID = $client->newRewriteRule([
   'condition' => $condition,
   'conseq' => $conseq
]);
$conseq['redirect']['url'] = '/cn/2018/';
$ok = $client->updateRewriteRule([
   'rule_id' => $rewriteRuleID,
   'conseq' => $conseq
]);
?>
deleteRewriteRule
$ok = deleteRewriteRule($ruleID);
Example:
<?php
require_once(__DIR__ . '/vendor/autoload.php');
use OpenResty\Edge2Client;
$client = new Edge2Client([
   'edge_admin_addr' => 'https://admin.openresty.com',
   'username' => 'admin',
   'password' => '123456'
]);
$ok = $client->login();
$appID = $client->newApp([
   'domains' => ['orig.foo.com'],
   'label' => 'origin site for foo.com',
]);
$condition = [
    ['var' => 'host', 'op' => 'eq', 'val' => "con.foo.com"],
    ['var' => ['req-header', 'Referer'], 'vals' => [['foo\d+','rx'], 'foo.com']]
];
$conseq = [
    'print' => ['msg' => 'hello'],
    enable-'websocket' => [],
    'redirect' => ['url' => '/cn/2017/', 'code' => 302]
];
$rewriteRuleID = $client->newRewriteRule([
   'condition' => $condition,
   'conseq' => $conseq
]);
$ok = $client->deleteRewriteRule($rewriteRuleID);
?>
newAppDymetrics
$metric = newAppDymetrics($opts);
Description of array $opts:
| Key name | Type | Required | Description | 
|---|---|---|---|
| name | string | yes | dynamic metric name | 
| interval | int | yes | dynamic metric aggregate interval | 
| sql | string | yes | dynamic metric SQL | 
Example:
<?php
require_once(__DIR__ . '/vendor/autoload.php');
use OpenResty\Edge2Client;
$client = new Edge2Client([
   'edge_admin_addr' => 'https://admin.openresty.com',
   'username' => 'admin',
   'password' => '123456'
]);
$ok = $client->login();
$appID = $client->newApp([
   'domains' => ['orig.foo.com'],
   'label' => 'origin site for foo.com',
]);
$dymetric = [
   'name' => 'test',
   'interval' => 60,
   'sql' => 'select status, count(*) from reqs group by status'
];
$metric = $client->newAppDymetrics($dymetric);
?>
deleteAppDymetrics
$ok = deleteAppDymetrics($metricID);
Example:
<?php
require_once(__DIR__ . '/vendor/autoload.php');
use OpenResty\Edge2Client;
$client = new Edge2Client([
   'edge_admin_addr' => 'https://admin.openresty.com',
   'username' => 'admin',
   'password' => '123456'
]);
$ok = $client->login();
$appID = $client->newApp([
   'domains' => ['orig.foo.com'],
   'label' => 'origin site for foo.com',
]);
$opts = [
   'name' => 'test',
   'interval' => 60,
   'sql' => 'select status, count(*) from reqs group by status'
];
$metric = $client->newAppDymetrics($opts);
$ok = $client->deleteAppDymetrics($metric)
?>
getAppDymetrics
$metrics = getAppDymetrics();
Example:
<?php
require_once(__DIR__ . '/vendor/autoload.php');
use OpenResty\Edge2Client;
$client = new Edge2Client([
   'edge_admin_addr' => 'https://admin.openresty.com',
   'username' => 'admin',
   'password' => '123456'
]);
$ok = $client->login();
$appID = $client->newApp([
   'domains' => ['orig.foo.com'],
   'label' => 'origin site for foo.com',
]);
$opts = [
   'name' => 'test',
   'interval' => 60,
   'sql' => 'select status, count(*) from reqs group by status'
];
$metric = $client->newAppDymetrics($opts);
$metrics = $client->getAppDymetrics();
?>
getAppDymetricsData
$data = getAppDymetricsData($opts);
Description of array $opts:
| Key name | Type | Required | Description | 
|---|---|---|---|
| id | string | yes | dynamic metric id | 
| chart_type | string | yes | chart type: line, pie, bar | 
| start_time | int | yes | query start time | 
| end_time | int | yes | query end time | 
| node_id | string | no | gateway node id | 
Example:
<?php
require_once(__DIR__ . '/vendor/autoload.php');
use OpenResty\Edge2Client;
$client = new Edge2Client([
   'edge_admin_addr' => 'https://admin.openresty.com',
   'username' => 'admin',
   'password' => '123456'
]);
$ok = $client->login();
$appID = $client->newApp([
   'domains' => ['orig.foo.com'],
   'label' => 'origin site for foo.com',
]);
$opts = [
   'name' => 'test',
   'interval' => 60,
   'sql' => 'select status, count(*) from reqs group by status'
];
$metric = $client->newAppDymetrics($opts);
$opts = [
   'id' => $metric['id'],
   'chart_type' => 'line',
   'start_time' => 1619014008,
   'end_time' => 1619015008
];
data = $client->getAppDymetricsData($opts);
?>
newAppIPList
$appIPListID = newAppIPList($opts)
Description of object $opts:
| Key name | Type | Required | Description | 
|---|---|---|---|
| name | string | yes | the name of the IP list | 
| type | string | no | ipv4oripv6here (ipv6is not supported yet) | 
| items | array | no | $itemarray list | 
Description of object $item:
| Key name | Type | Required | Description | 
|---|---|---|---|
| ip | string | yes | one IP Address or one CIDR IP | 
Example:
<?php
require_once(__DIR__ . '/vendor/autoload.php');
use OpenResty\Edge2Client;
// use username and password
$client = new Edge2Client([
   'edge_admin_addr' => 'https://admin.openresty.com',
   'username' => 'admin',
   'password' => '123456'
]);
$ok = $client->login();
$appID = $client->newApp([
   'domains' => ['orig.foo.com'],
   'label' => 'origin site for foo.com',
]);
$appIPListID = $client->newAppIPList([
    'name' => 'app-iplist-1',
    'type' => 'ipv4',
    'items' => [
        [ 'ip' => '127.0.0.1' ],
        [ 'ip' => '192.168.1.0/24' ]
    ]
]);
?>
deleteAppIPList
$ok = deleteAppIPList($appIPListID)
Example:
<?php
require_once(__DIR__ . '/vendor/autoload.php');
use OpenResty\Edge2Client;
// use username and password
$client = new Edge2Client([
   'edge_admin_addr' => 'https://admin.openresty.com',
   'username' => 'admin',
   'password' => '123456'
]);
$ok = $client->login();
$appID = $client->newApp([
   'domains' => ['orig.foo.com'],
   'label' => 'origin site for foo.com',
]);
$appIPListID = $client->newGlobalIPList([
    'name' => 'iplist-1',
    'type' => 'ipv4',
    'items' => [
        [ 'ip' => '127.0.0.2' ],
        [ 'ip' => '192.168.1.0/24' ]
    ]
]);
$ok = $client->deleteAppIPList($appIPListID);
?>
updateAppIPList
Update the application-level IP list, which will overwrite the original data.
$ok = updateAppIPList($opts)
Description of object $opts:
| Key name | Type | Required | Description | 
|---|---|---|---|
| appIPListID | number | yes | ID of the IP list | 
| name | string | no | the name of the IP list | 
| type | string | no | ipv4oripv6here (ipv6is not supported yet) | 
| items | array | no | $itemarray list | 
Description of object $item:
| Key name | Type | Required | Description | 
|---|---|---|---|
| ip | string | no | one IP Address or one CIDR IP | 
Example:
<?php
require_once(__DIR__ . '/vendor/autoload.php');
use OpenResty\Edge2Client;
// use username and password
$client = new Edge2Client([
   'edge_admin_addr' => 'https://admin.openresty.com',
   'username' => 'admin',
   'password' => '123456'
]);
$ok = $client->login();
$appID = $client->newApp([
   'domains' => ['orig.foo.com'],
   'label' => 'origin site for foo.com',
]);
$ok = $client->updateAppIPList([
    'appIPListID' => 1,
    'items' => [
        [ 'ip' => '127.0.0.2' ],
        [ 'ip' => '192.168.1.0/24' ]
    ]
]);
?>
appendToAppIPList
Update the application-level IP list, which will not overwrite the original data.
$ok = appendToAppIPList($opts)
Description of object $opts:
| Key name | Type | Required | Description | 
|---|---|---|---|
| appIPListID | number | yes | ID of the IP list | 
| items | array | yes | $itemarray list | 
Description of object $item:
| Key name | Type | Required | Description | 
|---|---|---|---|
| ip | string | no | one IP Address or one CIDR IP | 
Example:
<?php
require_once(__DIR__ . '/vendor/autoload.php');
use OpenResty\Edge2Client;
// use username and password
$client = new Edge2Client([
   'edge_admin_addr' => 'https://admin.openresty.com',
   'username' => 'admin',
   'password' => '123456'
]);
$ok = $client->login();
$appID = $client->newApp([
   'domains' => ['orig.foo.com'],
   'label' => 'origin site for foo.com',
]);
$ok = $client->appendToAppIPList([
    'appIPListID' => 1,
    'items' => [
        [ 'ip' => '127.0.0.3' ]
    ]
]);
?>
removeFromAppIPList
Remove IPs from application-level IP list, which will not overwrite the original data.
$ok = removeFromAppIPList($opts)
Description of object $opts:
| Key name | Type | Required | Description | 
|---|---|---|---|
| appIPListID | number | yes | ID of the IP list | 
| items | array | yes | $itemarray list | 
Description of object $item:
| Key name | Type | Required | Description | 
|---|---|---|---|
| ip | string | no | one IP Address or one CIDR IP | 
Example:
<?php
require_once(__DIR__ . '/vendor/autoload.php');
use OpenResty\Edge2Client;
// use username and password
$client = new Edge2Client([
   'edge_admin_addr' => 'https://admin.openresty.com',
   'username' => 'admin',
   'password' => '123456'
]);
$ok = $client->login();
$appID = $client->newApp([
   'domains' => ['orig.foo.com'],
   'label' => 'origin site for foo.com',
]);
$ok = $client->removeFromAppIPList([
    'appIPListID' => 1,
    'items' => [
        [ 'ip' => '127.0.0.3' ]
    ]
]);
?>
getAppIPList
$data = getAppIPList($appIPListID)
Example:
<?php
require_once(__DIR__ . '/vendor/autoload.php');
use OpenResty\Edge2Client;
$client = new Edge2Client([
   'edge_admin_addr' => 'https://admin.openresty.com',
   'username' => 'admin',
   'password' => '123456'
]);
$ok = $client->login();
$appID = $client->newApp([
   'domains' => ['orig.foo.com'],
   'label' => 'origin site for foo.com',
]);
$ipList = $client->getAppIPList($appIPListID);
?>
getAllAppIPList
$data = getAllAppIPList()
Example:
<?php
require_once(__DIR__ . '/vendor/autoload.php');
use OpenResty\Edge2Client;
$client = new Edge2Client([
   'edge_admin_addr' => 'https://admin.openresty.com',
   'username' => 'admin',
   'password' => '123456'
]);
$ok = $client->login();
$appID = $client->newApp([
   'domains' => ['orig.foo.com'],
   'label' => 'origin site for foo.com',
]);
$ipList = $client->getAllAppIPList();
?>
setCertKey
$certID = setCertKey($opts)
Description of array $opts:
| Key name | Type | Required | Description | 
|---|---|---|---|
| key | string | yes | content of private key | 
| cert | string | yes | content of server cert | 
| caChain | string | no | content of CA chain | 
| global_cert_id | int | no | id of global cert | 
Example:
<?php
require_once(__DIR__ . '/vendor/autoload.php');
use OpenResty\Edge2Client;
$client = new Edge2Client([
   'edge_admin_addr' => 'https://admin.openresty.com',
   'username' => 'admin',
   'password' => '123456'
]);
$ok = $client->login();
$appID = $client->newApp([
   'domains' => ['orig.foo.com'],
   'label' => 'origin site for foo.com',
]);
$key = file_get_contents('tests/key.pem');
$cert = file_get_contents('tests/cert.pem');
$certID = $client->setCertKey([
   'key' => $key,
   'cert' => $cert
]);
?>
updateCertKey
$certID = updateCertKey($opts)
Description of array $opts:
| Key name | Type | Required | Description | 
|---|---|---|---|
| cert_id | int | yes | id of cert | 
| key | string | yes | content of private key | 
| cert | string | yes | content of server cert | 
| caChain | string | no | content of CA chain | 
| global_cert_id | int | no | id of global cert | 
Example:
<?php
require_once(__DIR__ . '/vendor/autoload.php');
use OpenResty\Edge2Client;
$client = new Edge2Client([
   'edge_admin_addr' => 'https://admin.openresty.com',
   'username' => 'admin',
   'password' => '123456'
]);
$ok = $client->login();
$appID = $client->newApp([
   'domains' => ['orig.foo.com'],
   'label' => 'origin site for foo.com',
]);
$key = file_get_contents('tests/key.pem');
$cert = file_get_contents('tests/cert.pem');
$certID = $client->setCertKey([
   'key' => $key,
   'cert' => $cert
]);
$ok = $client->updateCertKey(['cert_id' => $certID, 'key' => $key, 'cert' => $cert]);
?>
getCertKey
$data = getCertKey($certID)
Description of array $opts:
| Key name | Type | Required | Description | 
|---|---|---|---|
| cert_id | int | yes | id of cert | 
Example:
<?php
require_once(__DIR__ . '/vendor/autoload.php');
use OpenResty\Edge2Client;
$client = new Edge2Client([
   'edge_admin_addr' => 'https://admin.openresty.com',
   'username' => 'admin',
   'password' => '123456'
]);
$ok = $client->login();
$appID = $client->newApp([
   'domains' => ['orig.foo.com'],
   'label' => 'origin site for foo.com',
]);
$key = file_get_contents('tests/key.pem');
$cert = file_get_contents('tests/cert.pem');
$certID = $client->setCertKey([
   'key' => $key,
   'cert' => $cert
]);
$data = $client->getCertKey($certID);
?>
getAllCertKeys
$data = getAllCertKeys($appID)
Description of array $opts:
| Key name | Type | Required | Description | 
|---|---|---|---|
| AppID | int | no | id of app, default is current app’s id | 
Example:
<?php
require_once(__DIR__ . '/vendor/autoload.php');
use OpenResty\Edge2Client;
$client = new Edge2Client([
   'edge_admin_addr' => 'https://admin.openresty.com',
   'username' => 'admin',
   'password' => '123456'
]);
$ok = $client->login();
$appID = $client->newApp([
   'domains' => ['orig.foo.com'],
   'label' => 'origin site for foo.com',
]);
$key = file_get_contents('tests/key.pem');
$cert = file_get_contents('tests/cert.pem');
$certID = $client->setCertKey([
   'key' => $key,
   'cert' => $cert
]);
$data = $client->getAllCertKeys();
?>
deleteCertKey
$ok = deleteCertKey($certID);
Example:
<?php
require_once(__DIR__ . '/vendor/autoload.php');
use OpenResty\Edge2Client;
$client = new Edge2Client([
   'edge_admin_addr' => 'https://admin.openresty.com',
   'username' => 'admin',
   'password' => '123456'
]);
$ok = $client->login();
$appID = $client->newApp([
   'domains' => ['orig.foo.com'],
   'label' => 'origin site for foo.com',
]);
$key = file_get_contents('tests/key.pem');
$cert = file_get_contents('tests/cert.pem');
$certID = $client->setCertKey([
   'key' => $key,
   'cert' => $cert
]);
$ok = $client->deleteCertKey($certID);
?>
setGlobalCertKey
$certID = setGlobalCertKey($opts)
Description of array $opts:
| Key name | Type | Required | Description | 
|---|---|---|---|
| key | string | yes | content of private key | 
| cert | string | yes | content of server cert | 
| caChain | string | no | content of CA chain | 
Example:
<?php
require_once(__DIR__ . '/vendor/autoload.php');
use OpenResty\Edge2Client;
$client = new Edge2Client([
   'edge_admin_addr' => 'https://admin.openresty.com',
   'username' => 'admin',
   'password' => '123456'
]);
$ok = $client->login();
$key = file_get_contents('tests/key.pem');
$cert = file_get_contents('tests/cert.pem');
$certID = $client->setGlobalCertKey([
   'key' => $key,
   'cert' => $cert
]);
?>
updateGlobalCertKey
$ok = updateGlobalCertKey($opts)
Description of array $opts:
| Key name | Type | Required | Description | 
|---|---|---|---|
| cert_id | int | yes | id of cert | 
| key | string | yes | content of private key | 
| cert | string | yes | content of server cert | 
| caChain | string | no | content of CA chain | 
Example:
<?php
require_once(__DIR__ . '/vendor/autoload.php');
use OpenResty\Edge2Client;
$client = new Edge2Client([
   'edge_admin_addr' => 'https://admin.openresty.com',
   'username' => 'admin',
   'password' => '123456'
]);
$ok = $client->login();
$key = file_get_contents('tests/key.pem');
$cert = file_get_contents('tests/cert.pem');
$certID = $client->setGlobalCertKey([
   'key' => $key,
   'cert' => $cert
]);
$ok = $client->updateGlobalCertKey(['cert_id' => $certID, 'key' => $key, 'cert' => $cert]);
?>
getGlobalCertKey
$data = getGlobalCertKey($certID)
Description of array $opts:
| Key name | Type | Required | Description | 
|---|---|---|---|
| certID | int | yes | id of cert | 
Example:
<?php
require_once(__DIR__ . '/vendor/autoload.php');
use OpenResty\Edge2Client;
$client = new Edge2Client([
   'edge_admin_addr' => 'https://admin.openresty.com',
   'username' => 'admin',
   'password' => '123456'
]);
$ok = $client->login();
$key = file_get_contents('tests/key.pem');
$cert = file_get_contents('tests/cert.pem');
$certID = $client->setGlobalCertKey([
   'key' => $key,
   'cert' => $cert
]);
$data = $client->getGlobalCertKey($certID);
?>
getAllGlobalCertKeys
$data = getAllGlobalCertKeys()
Example:
<?php
require_once(__DIR__ . '/vendor/autoload.php');
use OpenResty\Edge2Client;
$client = new Edge2Client([
   'edge_admin_addr' => 'https://admin.openresty.com',
   'username' => 'admin',
   'password' => '123456'
]);
$ok = $client->login();
$key = file_get_contents('tests/key.pem');
$cert = file_get_contents('tests/cert.pem');
$certID = $client->setGlobalCertKey([
   'key' => $key,
   'cert' => $cert
]);
$data = $client->getAllGlobalCertKeys();
?>
deleteGlobalCertKey
$ok = deleteGlobalCertKey($certID);
Example:
<?php
require_once(__DIR__ . '/vendor/autoload.php');
use OpenResty\Edge2Client;
$client = new Edge2Client([
   'edge_admin_addr' => 'https://admin.openresty.com',
   'username' => 'admin',
   'password' => '123456'
]);
$ok = $client->login();
$key = file_get_contents('tests/key.pem');
$cert = file_get_contents('tests/cert.pem');
$certID = $client->setGlobalCertKey([
   'key' => $key,
   'cert' => $cert
]);
$ok = $client->deleteGlobalCertKey($certID);
?>
newCachePurgeTask
$taskID = newCachePurgeTask($opts)
Description of array $opts:
| Key name | Type | Required | Description | 
|---|---|---|---|
| type | string | no | one of urlsorconditional, default isconditional | 
| note | string | no | note of purge task | 
| condition | list | no | conditions of task when typeisconditional | 
| urls | array | no | urls needs to be refreshed when typeisurls. url must belong to this application and starts withhttporhttps. | 
Example:
<?php
require_once(__DIR__ . '/vendor/autoload.php');
use OpenResty\Edge2Client;
$client = new Edge2Client([
   'edge_admin_addr' => 'https://admin.openresty.com',
   'username' => 'admin',
   'password' => '123456'
]);
$ok = $client->login();
$appID = $client->newApp([
   'domains' => ['test.com'],
   'label' => 'origin site for test.com',
]);
$condition = [
            ['var' => 'uri', 'op' => 'prefix', 'val' => '/foo']
        ];
$task_id = $client->newCachePurgeTask(['condition' => $condition]);
$task_id = $client->newCachePurgeTask(['type' => 'urls', 'urls' => array('http://test.com/foo', 'http://test.com/bar', 'http://test.com/abc/ddd')]);
?>
getCachePurgeTask
$data = getCachePurgeTask($taskID)
Description of array $opts:
| Key name | Type | Required | Description | 
|---|---|---|---|
| taskID | int | yes | id of cache purge task | 
Example:
<?php
require_once(__DIR__ . '/vendor/autoload.php');
use OpenResty\Edge2Client;
$client = new Edge2Client([
   'edge_admin_addr' => 'https://admin.openresty.com',
   'username' => 'admin',
   'password' => '123456'
]);
$ok = $client->login();
$condition = [
            ['var' => 'uri', 'op' => 'prefix', 'val' => '/foo']
        ];
$task_id = $client->newCachePurgeTask(['condition' => $condition]);
$data = $client->getCachePurgeTask($task_id);
?>
getAllCachePurgeTasks
$data = getAllCachePurgeTasks()
Example:
<?php
require_once(__DIR__ . '/vendor/autoload.php');
use OpenResty\Edge2Client;
$client = new Edge2Client([
   'edge_admin_addr' => 'https://admin.openresty.com',
   'username' => 'admin',
   'password' => '123456'
]);
$ok = $client->login();
$condition = [
            ['var' => 'uri', 'op' => 'prefix', 'val' => '/foo']
        ];
$task_id = $client->newCachePurgeTask(['condition' => $condition]);
$data = $client->getAllCachePurgeTasks();
?>
deleteCachePurgeTask
$ok = deleteCachePurgeTask($taskID);
Example:
<?php
require_once(__DIR__ . '/vendor/autoload.php');
use OpenResty\Edge2Client;
$client = new Edge2Client([
   'edge_admin_addr' => 'https://admin.openresty.com',
   'username' => 'admin',
   'password' => '123456'
]);
$ok = $client->login();
$condition = [
            ['var' => 'uri', 'op' => 'prefix', 'val' => '/foo']
        ];
$task_id = $client->newCachePurgeTask(['condition' => $condition]);
$ok = $client->deleteCachePurgeTask($task_id);
?>
newEL
$certID = newEL($opts)
Description of array $opts:
| Key name | Type | Required | Description | 
|---|---|---|---|
| phase | string | yes | phase | 
| code | string | yes | edgelang code | 
| post | bool | yes | put EL code to then end of phaseif set totrue, else put to the front ofphase | 
Example:
<?php
require_once(__DIR__ . '/vendor/autoload.php');
use OpenResty\Edge2Client;
$client = new Edge2Client([
   'edge_admin_addr' => 'https://admin.openresty.com',
   'username' => 'admin',
   'password' => '123456'
]);
$ok = $client->login();
$appID = $client->newApp([
   'domains' => ['orig.foo.com'],
   'label' => 'origin site for foo.com',
]);
$code = "'true' => print('hello, foo.com');";
$ok = $client->newEL([
   'phase' => 'req-rewrite',
   'code' => $code,
   'post' => false
]);
?>
newRelease
$ok = newRelease()
Example:
<?php
require_once(__DIR__ . '/vendor/autoload.php');
use OpenResty\Edge2Client;
$client = new Edge2Client([
   'edge_admin_addr' => 'https://admin.openresty.com',
   'username' => 'admin',
   'password' => '123456'
]);
$ok = $client->login();
$appID = $client->newApp([
   'domains' => ['orig.foo.com'],
   'label' => 'origin site for foo.com',
]);
$code = "'true' => print('hello, foo.com');";
$ok = $client->newEL([
   'phase' => 'req-rewrite',
   'code' => $code,
   'post' => false
]);
$ok = $client->newRelease();
?>
pendingChanges
$changes = pendingChanges()
Example:
<?php
require_once(__DIR__ . '/vendor/autoload.php');
use OpenResty\Edge2Client;
$client = new Edge2Client([
   'edge_admin_addr' => 'https://admin.openresty.com',
   'username' => 'admin',
   'password' => '123456'
]);
$ok = $client->login();
$appID = $client->newApp([
   'domains' => ['orig.foo.com'],
   'label' => 'origin site for foo.com',
]);
$code = "'true' => print('hello, foo.com');";
$ok = $client->newEL([
   'phase' => 'req-rewrite',
   'code' => $code,
   'post' => false
]);
$beforeChanges = $client->pendingChanges();
$ok = $client->newRelease();
$afterChanges = $client->pendingChanges();
?>
setWorker
$ok = setWorker($opts)
Description of array $opts:
| Key name | Type | Required | Description | 
|---|---|---|---|
| connections | number | no | worker connections; default is 10240 | 
| processes | string | no | worker processes; default is auto; should set to string"8"instead of 8 | 
| maxOpenFiles | number | no | the maximum number of open files (RLIMIT_NOFILE); default is 20480 | 
| backlog | number | no | listening socket’s backlog queue size; default is 511 | 
| enable_http2 | bool | no | default is false | 
Example:
<?php
require_once(__DIR__ . '/vendor/autoload.php');
use OpenResty\Edge2Client;
$client = new Edge2Client([
   'edge_admin_addr' => 'https://admin.openresty.com',
   'username' => 'admin',
   'password' => '123456'
]);
$ok = $client->login();
$ok = $client->setWorker([
   'connections' => 20480,
   'processes' => '8',
   'enable_http2' => true
]);
?>
setSSL
$ok = setSSL($opts)
Description of array $opts:
| Key name | Type | Required | Description | 
|---|---|---|---|
| session_ttl | number | no | session timeout; unit is minute; default is 1 day | 
| session_cache | number | no | the size of share memory to cache the SSL session; unit is MB; default is 32 MB | 
| protocols | array | no | default is [“TLSv1”,“TLSv1.1”,“TLSv1.2”] | 
| ciphers | string | no | SSL ciphers | 
| prefer_server_ciphers | bool | no | Specifies that server ciphers should be preferred over client ciphers when using the SSLv3 and TLS protocols; default is true | 
Example:
<?php
require_once(__DIR__ . '/vendor/autoload.php');
use OpenResty\Edge2Client;
$client = new Edge2Client([
   'edge_admin_addr' => 'https://admin.openresty.com',
   'username' => 'admin',
   'password' => '123456'
]);
$ok = $client->login();
$ok = $client->setSSL([
   'session_ttl' => 60,
   'session_cache' => 100,
   'protocols' => ["TLSv1","TLSv1.1","TLSv1.2"],
   'prefer_server_ciphers' => false
]);
?>
setProxy
$ok = setProxy($opts)
Description of array $opts:
| Key name | Type | Required | Description | 
|---|---|---|---|
| intercept_errors | bool | no | intercept proxy error response; default is false | 
| ignoreClientAbort | bool | no | determines whether the connection with a proxied server should be closed when a client closes the connection without waiting for a response; default is false | 
| buffer_size | number | no | proxy buffer size; unit is KB; default is 8 KB | 
| buffers_count | number | no | the number of the buffers; default is 8 | 
| buffers_size | number | no | the size of the buffers; unit is KB; default is 16 | 
| busy_buffers_size | number | no | the size of the busy buffers; unit is KB; default is 16 | 
| temp_file_write_size | number | no | proxy temporary file write size; unit is KB; default is 16 | 
Example:
<?php
require_once(__DIR__ . '/vendor/autoload.php');
use OpenResty\Edge2Client;
$client = new Edge2Client([
   'edge_admin_addr' => 'https://admin.openresty.com',
   'username' => 'admin',
   'password' => '123456'
]);
$ok = $client->login();
$ok = $client->setProxy([
   'intercept_errors' => true,
   'buffer_size' => 100
]);
?>
setClientReq
$ok = setClientReq($opts)
Description of array $opts:
| Key name | Type | Required | Description | 
|---|---|---|---|
| body_timeout | number | no | reading client request body timeout; unit is second; default is 60 | 
| header_timeout | number | no | reading client request header timeout; unit is second; default is 60 | 
Example:
<?php
require_once(__DIR__ . '/vendor/autoload.php');
use OpenResty\Edge2Client;
$client = new Edge2Client([
   'edge_admin_addr' => 'https://admin.openresty.com',
   'username' => 'admin',
   'password' => '123456'
]);
$ok = $client->login();
$ok = $client->setClientReq([
   'body_timeout' => 30,
   'header_timeout' => 100
]);
?>
setFileBuffer
$ok = setFileBuffer($opts)
Description of array $opts:
| Key name | Type | Required | Description | 
|---|---|---|---|
| enable_cache | bool | no | enable open file cache; default is true | 
| max_cache | number | no | maximum cached number of elements; default is 1000 | 
| inactive_ttl | number | no | Inactive TTL (second); default is 60 | 
Example:
<?php
require_once(__DIR__ . '/vendor/autoload.php');
use OpenResty\Edge2Client;
$client = new Edge2Client([
   'edge_admin_addr' => 'https://admin.openresty.com',
   'username' => 'admin',
   'password' => '123456'
]);
$ok = $client->login();
$ok = $client->setFileBuffer([
   'max_cache' => 2000,
   'inactive_ttl' => 30
]);
?>
setLog
$ok = setLog($opts)
Description of array $opts:
| Key name | Type | Required | Description | 
|---|---|---|---|
| no_errLog | bool | no | avoid generating error logs; default is false | 
| log_level | string | no | error log level; default is info | 
| max_log_files | number | no | maximum number of log files to keep; default is 168 | 
Example:
<?php
require_once(__DIR__ . '/vendor/autoload.php');
use OpenResty\Edge2Client;
$client = new Edge2Client([
   'edge_admin_addr' => 'https://admin.openresty.com',
   'username' => 'admin',
   'password' => '123456'
]);
$ok = $client->login();
$ok = $client->setLog([
   'no_errLog' => false,
   'log_level' => 'error',
   'max_log_files' => 100
]);
?>
setDNS
$ok = setDNS($opts)
global config of DNS.
Description of array $opts:
| Key name | Type | Required | Description | 
|---|---|---|---|
| enable_dns | bool | no | enable DNS; default is true | 
| resolvers | array | no | resolvers of DNS; default is ["114.114.114.114", "8.8.8.8"] | 
| timeout | number | no | DNS resolver timeout(second); default is 5 seconds | 
Example:
<?php
require_once(__DIR__ . '/vendor/autoload.php');
use OpenResty\Edge2Client;
$client = new Edge2Client([
   'edge_admin_addr' => 'https://admin.openresty.com',
   'username' => 'admin',
   'password' => '123456'
]);
$ok = $client->login();
$ok = $client->setDNS([
   'timeout' => 10,
   'resolvers' => ['114.114.114.114']
]);
?>
setGzip
$ok = setGzip($opts)
global config of DNS.
Description of array $opts:
| Key name | Type | Required | Description | 
|---|---|---|---|
| enable_gzip | bool | no | enable Gzip; default is false | 
| http_version | string | no | one of 1.0and1.1; default is1.1 | 
| buffers | number | no | the number of buffers; default is 32 | 
| buffer_size | number | no | size of each buffer; unit is KB; default is 4 | 
| compression_level | number | no | the level of compression level; default is 1 | 
| min_length | number | no | minimum response body size for Gzip compression; default is 20 | 
| disable_ie6 | bool | no | Disable Gzip for IE6; default is true | 
Example:
<?php
require_once(__DIR__ . '/vendor/autoload.php');
use OpenResty\Edge2Client;
$client = new Edge2Client([
   'edge_admin_addr' => 'https://admin.openresty.com',
   'username' => 'admin',
   'password' => '123456'
]);
$ok = $client->login();
$ok = $client->setGzip([
   'enable_gzip' => true,
   'buffers' => 64,
   'compression_level' => 6
]);
?>
newDNS
$appID = newDNS($opts)
Description of array $opts:
| Key name | Type | Required | Description | 
|---|---|---|---|
| zone | string | yes | domain of DNS | 
| authority | array | yes | server names of DNS | 
| soa_email | string | no | soa email of DNS | 
Example:
<?php
require_once(__DIR__ . '/vendor/autoload.php');
use OpenResty\Edge2Client;
$client = new Edge2Client([
   'edge_admin_addr' => 'https://admin.openresty.com',
   'username' => 'admin',
   'password' => '123456'
]);
$ok = $client->login();
$authority = [
    ['domain' => "ns1.foo.com",'ttl' => '2 hour'],
    ['domain' => "ns2.foo.com",'ttl' => '1 day'],
];
$dnsID = $client->newDNS([
   'authority' => $authority,
   'soa_email' => 'admin.foo.com',
   'zone' => 'foo.com'
]);
?>
updateDNS
$ok = updateDNS($opts);
Description of array $opts:
| Key name | Type | Required | Description | 
|---|---|---|---|
| dnsID | number | yes | id of DNS | 
| zone | string | yes | domain of DNS | 
| authority | array | yes | server names of DNS | 
| soa_email | string | no | soa email of DNS | 
Example:
<?php
require_once(__DIR__ . '/vendor/autoload.php');
use OpenResty\Edge2Client;
$client = new Edge2Client([
   'edge_admin_addr' => 'https://admin.openresty.com',
   'username' => 'admin',
   'password' => '123456'
]);
$ok = $client->login();
$authority = [
    ['domain' => "ns1.foo.com", 'ttl' => '2 hour'],
    ['domain' => "ns2.foo.com", 'ttl' => '1 day'],
];
$dnsID = $client->newDNS([
   'authority' => $authority,
   'soa_email' => 'admin.foo.com',
   'zone' => 'foo.com'
]);
$data = self::$client->getDNS(self::$dns_id);
$authority = [
    ['domain' => "ns1.foo.com", 'ttl' => '1 hour', 'id' => $data['nameserver'][0]'id'],
    ['domain' => "ns2.foo.com", 'ttl' => '1 hour', 'id' =>  $data['nameserver'][1]['id']],
    ['domain' => "ns3.foo.com", 'ttl' => '1 hour']
];
$ok = $client->updateDNS(['dns_id' => $dnsID,
                       'authority' => $authority,'zone' => 'foo.com']);
?>
deleteDNS
$ok = deleteDNS($dnsID);
Example:
<?php
require_once(__DIR__ . '/vendor/autoload.php');
use OpenResty\Edge2Client;
$client = new Edge2Client([
   'edge_admin_addr' => 'https://admin.openresty.com',
   'username' => 'admin',
   'password' => '123456'
]);
$ok = $client->login();
$authority = [
    ['domain' => "ns1.foo.com", 'ttl' => '2 hour'],
    ['domain' => "ns2.foo.com", 'ttl' => '1 day'],
];
$dnsID = $client->newDNS([
   'authority' => $authority,
   'soa_email' => 'admin.foo.com',
   'zone' => 'foo.com'
]);
$ok = $client->deleteDNS($dnsID);
?>
newDnsRecord
$appID = newDnsRecord($opts)
Description of array $opts:
| Key name | Type | Required | Description | 
|---|---|---|---|
| dnsID | number | yes | id of DNS | 
| sub_domain | string | yes | sub domain | 
| line | number | false | line, default 0 | 
| cidr | string | false | cidr | 
| type | string | yes | type of record, one of [A, TXT, MX, CNAME] | 
| text | string | no | required if typeisTXT | 
| ip | string | no | required if typeisA | 
| domain | string | no | required if typeisCNAME | 
| priority | number | no | required if typeisMX | 
Example:
<?php
require_once(__DIR__ . '/vendor/autoload.php');
use OpenResty\Edge2Client;
$client = new Edge2Client([
   'edge_admin_addr' => 'https://admin.openresty.com',
   'username' => 'admin',
   'password' => '123456'
]);
$ok = $client->login();
$authority = [
    ['domain' => "ns1.foo.com",'ttl' => '2 hour'],
    ['domain' => "ns2.foo.com",'ttl' => '1 day'],
];
$dnsID = $client->newDNS([
   'authority' => $authority,
   'soa_email' => 'admin.foo.com',
   'zone' => 'foo.com'
]);
$record_id = $client->newDnsRecord([
   'dns_id' => $dnsID,
   'sub_domain' => 'bar',
   'line' => 0,
   'type' => 'TXT',
   'text' => 'text string'
]);
?>
updateDnsRecord
$appID = updateDnsRecord($opts)
Description of array $opts:
| Key name | Type | Required | Description | 
|---|---|---|---|
| dnsID | number | yes | id of DNS | 
| record_id | number | yes | record id of DNS | 
| sub_domain | string | yes | sub domain | 
| line | number | false | line, default 0 | 
| cidr | string | false | cidr | 
| type | string | yes | type of record, one of [A, TXT, MX, CNAME] | 
| text | string | no | required if typeisTXT | 
| ip | string | no | required if typeisA | 
| domain | string | no | required if typeisCNAME | 
| priority | number | no | required if typeisMX | 
Example:
<?php
require_once(__DIR__ . '/vendor/autoload.php');
use OpenResty\Edge2Client;
$client = new Edge2Client([
   'edge_admin_addr' => 'https://admin.openresty.com',
   'username' => 'admin',
   'password' => '123456'
]);
$ok = $client->login();
$authority = [
    ['domain' => "ns1.foo.com",'ttl' => '2 hour'],
    ['domain' => "ns2.foo.com",'ttl' => '1 day'],
];
$dnsID = $client->newDNS([
   'authority' => $authority,
   'soa_email' => 'admin.foo.com',
   'zone' => 'foo.com'
]);
$record_id = $client->newDnsRecord([
   'dns_id' => $dnsID,
   'sub_domain' => 'bar',
   'line' => 0,
   'type' => 'TXT',
   'text' => 'text string'
]);
$ok = $client->updateDnsRecord([
   'dns_id' => $dnsID,
   'record_id' => $record_id,
   'sub_domain' => 'a.bar',
   'line' => 0,
   'type' => 'TXT',
   'text' => 'text string'
]);
?>
deleteDnsRecord
$appID = deleteDnsRecord($opts)
Description of array $opts:
| Key name | Type | Required | Description | 
|---|---|---|---|
| dnsID | number | yes | id of DNS | 
| record_id | number | yes | record id of DNS | 
Example:
<?php
require_once(__DIR__ . '/vendor/autoload.php');
use OpenResty\Edge2Client;
$client = new Edge2Client([
   'edge_admin_addr' => 'https://admin.openresty.com',
   'username' => 'admin',
   'password' => '123456'
]);
$ok = $client->login();
$authority = [
    ['domain' => "ns1.foo.com",'ttl' => '2 hour'],
    ['domain' => "ns2.foo.com",'ttl' => '1 day'],
];
$dnsID = $client->newDNS([
   'authority' => $authority,
   'soa_email' => 'admin.foo.com',
   'zone' => 'foo.com'
]);
$record_id = $client->newDnsRecord([
   'dns_id' => $dnsID,
   'sub_domain' => 'bar',
   'line' => 0,
   'type' => 'TXT',
   'text' => 'text string'
]);
$ok = $client->deleteDnsRecord([
   'dns_id' => $dnsID,
   'record_id' => $record_id
]);
?>
disabledDnsRecord
$appID = disabledDnsRecord($opts)
Description of array $opts:
| Key name | Type | Required | Description | 
|---|---|---|---|
| dnsID | number | yes | id of DNS | 
| record_id | number | yes | record id of DNS | 
Example:
<?php
require_once(__DIR__ . '/vendor/autoload.php');
use OpenResty\Edge2Client;
$client = new Edge2Client([
   'edge_admin_addr' => 'https://admin.openresty.com',
   'username' => 'admin',
   'password' => '123456'
]);
$ok = $client->login();
$authority = [
    ['domain' => "ns1.foo.com",'ttl' => '2 hour'],
    ['domain' => "ns2.foo.com",'ttl' => '1 day'],
];
$dnsID = $client->newDNS([
   'authority' => $authority,
   'soa_email' => 'admin.foo.com',
   'zone' => 'foo.com'
]);
$record_id = $client->newDnsRecord([
   'dns_id' => $dnsID,
   'sub_domain' => 'bar',
   'line' => 0,
   'type' => 'TXT',
   'text' => 'text string'
]);
$ok = $client->disabledDnsRecord([
   'dns_id' => $dnsID,
   'record_id' => $record_id
]);
?>
newGlobalDymetrics
$metric = newGlobalDymetrics($opts);
Description of array $opts:
| Key name | Type | Required | Description | 
|---|---|---|---|
| name | string | yes | dynamic metric name | 
| interval | int | yes | dynamic metric aggregate interval | 
| sql | string | yes | dynamic metric SQL | 
Example:
<?php
require_once(__DIR__ . '/vendor/autoload.php');
use OpenResty\Edge2Client;
$client = new Edge2Client([
   'edge_admin_addr' => 'https://admin.openresty.com',
   'username' => 'admin',
   'password' => '123456'
]);
$ok = $client->login();
$opts = [
   'name' => 'test',
   'interval' => 60,
   'sql' => 'select status, count(*) from reqs group by status'
];
$metric = $client->newGlobalDymetrics($opts);
?>
deleteGlobalDymetrics
$ok = deleteGlobalDymetrics($metricID);
Example:
<?php
require_once(__DIR__ . '/vendor/autoload.php');
use OpenResty\Edge2Client;
$client = new Edge2Client([
   'edge_admin_addr' => 'https://admin.openresty.com',
   'username' => 'admin',
   'password' => '123456'
]);
$ok = $client->login();
$opts = [
   'name' => 'test',
   'interval' => 60,
   'sql' => 'select status, count(*) from reqs group by status'
];
$metric = $client->newGlobalDymetrics($opts);
$ok = $client->deleteGlobalDymetrics($metric)
?>
getGlobalDymetrics
$metrics = getGlobalDymetrics();
Example:
<?php
require_once(__DIR__ . '/vendor/autoload.php');
use OpenResty\Edge2Client;
$client = new Edge2Client([
   'edge_admin_addr' => 'https://admin.openresty.com',
   'username' => 'admin',
   'password' => '123456'
]);
$ok = $client->login();
$opts = [
   'name' => 'test',
   'interval' => 60,
   'sql' => 'select status, count(*) from reqs group by status'
];
$metric = $client->newGlobalDymetrics($opts);
$metrics = $client->getGlobalDymetrics();
?>
getGlobalDymetricsData
$data = getGlobalDymetricsData($opts);
Description of array $opts:
| Key name | Type | Required | Description | 
|---|---|---|---|
| id | string | yes | dynamic metric id | 
| chart_type | string | yes | chart type: line, pie, bar | 
| start_time | int | yes | query start time | 
| end_time | int | yes | query end time | 
| node_id | string | no | gateway node id | 
Example:
<?php
require_once(__DIR__ . '/vendor/autoload.php');
use OpenResty\Edge2Client;
$client = new Edge2Client([
   'edge_admin_addr' => 'https://admin.openresty.com',
   'username' => 'admin',
   'password' => '123456'
]);
$ok = $client->login();
$opts = [
   'name' => 'test',
   'interval' => 60,
   'sql' => 'select status, count(*) from reqs group by status'
];
$metric = $client->newGlobalDymetrics($opts);
$opts = [
   'id' => $metric['id'],
   'chart_type' => 'line',
   'start_time' => 1619014008,
   'end_time' => 1619015008
];
data = $client->getGlobalDymetricsData($opts);
?>
getMetricData
$data = getMetricData($appID)
| Key name | Type | Required | Description | 
|---|---|---|---|
| appID | number | no | default is id of current app | 
Example:
<?php
require_once(__DIR__ . '/vendor/autoload.php');
use OpenResty\Edge2Client;
$client = new Edge2Client([
   'edge_admin_addr' => 'https://admin.openresty.com',
   'username' => 'admin',
   'password' => '123456'
]);
$ok = $client->login();
$appID = $client->newApp([
   'domains' => ['orig.foo.com'],
   'label' => 'origin site for foo.com',
]);
$data = $client->getMetricData();
?>
newLayerPolicy
$policyID = newLayerPolicy($opts)
Description of array $opts:
| Key name | Type | Required | Description | 
|---|---|---|---|
| name | string | yes | the policy name | 
| rules | array | yes | the policy rules | 
Description of array $rule:
| Key name | Type | Required | Description | 
|---|---|---|---|
| gateway | number | yes | current gateway id | 
| upstream | number | yes | upstream gateway id | 
| backup | number | no | backup upstream gateway id | 
Example:
<?php
require_once(__DIR__ . '/vendor/autoload.php');
use OpenResty\Edge2Client;
$client = new Edge2Client([
   'edge_admin_addr' => 'https://admin.openresty.com',
   'username' => 'admin',
   'password' => '123456'
]);
$ok = $client->login();
$policyID = $client->newLayerPolicy([
   'name' => 'policy_1',
   'rules' => [
      [
         "gateway" => 3,
         "upstream" => 2,
         "backup" => 1
      ]
   ]
]);
?>
deleteLayerPolicy
$ok = deleteLayerPolicy($policyID)
Description of $policyID:
| Key name | Type | Required | Description | 
|---|---|---|---|
| policyID | number | yes | the policy id | 
Example:
<?php
require_once(__DIR__ . '/vendor/autoload.php');
use OpenResty\Edge2Client;
$client = new Edge2Client([
   'edge_admin_addr' => 'https://admin.openresty.com',
   'username' => 'admin',
   'password' => '123456'
]);
$ok = $client->login();
$ok = $client->deleteLayerPolicy(1);
?>
updateLayerPolicy
$ok = updateLayerPolicy($opts)
Description of array $opts:
| Key name | Type | Required | Description | 
|---|---|---|---|
| policy_id | number | yes | the policy id | 
| name | string | yes | the policy name | 
| rules | array | yes | the policy rules | 
Description of array $rule:
| Key name | Type | Required | Description | 
|---|---|---|---|
| gateway | number | yes | current gateway id | 
| upstream | number | yes | upstream gateway id | 
| backup | number | no | backup upstream gateway id | 
Example:
<?php
require_once(__DIR__ . '/vendor/autoload.php');
use OpenResty\Edge2Client;
$client = new Edge2Client([
   'edge_admin_addr' => 'https://admin.openresty.com',
   'username' => 'admin',
   'password' => '123456'
]);
$ok = $client->login();
$ok = $client->updateLayerPolicy([
   'policy_id' => 1,
   'name' => 'policy_2',
   'rules' => [
      [
         "gateway" => 3,
         "upstream" => 2,
         "backup" => 1
      ]
   ]
]);
?>
getLayerPolicies
$data = getLayerPolicies()
<?php
require_once(__DIR__ . '/vendor/autoload.php');
use OpenResty\Edge2Client;
$client = new Edge2Client([
   'edge_admin_addr' => 'https://admin.openresty.com',
   'username' => 'admin',
   'password' => '123456'
]);
$ok = $client->login();
$policies = $client->getLayerPolicies();
?>
newGlobalIPList
$GlobalIPListID = newGlobalIPList($opts)
Description of object $opts:
| Key name | Type | Required | Description | 
|---|---|---|---|
| name | string | yes | the name of the IP list | 
| type | string | no | ipv4oripv6here (ipv6is not supported yet) | 
| items | array | no | $itemarray list | 
Description of object $item:
| Key name | Type | Required | Description | 
|---|---|---|---|
| ip | string | yes | one IP Address or one CIDR IP | 
Example:
<?php
require_once(__DIR__ . '/vendor/autoload.php');
use OpenResty\Edge2Client;
// use username and password
$client = new Edge2Client([
   'edge_admin_addr' => 'https://admin.openresty.com',
   'username' => 'admin',
   'password' => '123456'
]);
$ok = $client->login();
$globalIPListID = $client->newGlobalIPList([
    'name' => 'iplist-1',
    'type' => 'ipv4',
    'items' => [
        [ 'ip' => '127.0.0.1' ],
        [ 'ip' => '192.168.0.0/16' ]
    ]
]);
?>
deleteGlobalIPList
$ok = deleteGlobalIPList($globalIPListID)
Example:
<?php
require_once(__DIR__ . '/vendor/autoload.php');
use OpenResty\Edge2Client;
// use username and password
$client = new Edge2Client([
   'edge_admin_addr' => 'https://admin.openresty.com',
   'username' => 'admin',
   'password' => '123456'
]);
$ok = $client->login();
$globalIPListID = $client->newGlobalIPList([
    'name' => 'iplist-1',
    'type' => 'ipv4',
    'items' => [
        [ 'ip' => '127.0.0.1' ],
        [ 'ip' => '192.168.0.0/16' ]
    ]
]);
$ok = $client->deleteGlobalIPList($globalIPListID);
?>
updateGlobalIPList
Update the global IP list, which will overwrite the original data.
$ok = updateGlobalIPList($opts)
Description of object $opts:
| Key name | Type | Required | Description | 
|---|---|---|---|
| globalIPListID | number | yes | ID of the IP list | 
| name | string | no | the name of the IP list | 
| type | string | no | ipv4oripv6here (ipv6is not supported yet) | 
| items | array | no | $itemarray list | 
Description of object $item:
| Key name | Type | Required | Description | 
|---|---|---|---|
| ip | string | no | one IP Address or one CIDR IP | 
Example:
<?php
require_once(__DIR__ . '/vendor/autoload.php');
use OpenResty\Edge2Client;
// use username and password
$client = new Edge2Client([
   'edge_admin_addr' => 'https://admin.openresty.com',
   'username' => 'admin',
   'password' => '123456'
]);
$ok = $client->login();
$ok = $client->updateGlobalIPList([
    'globalIPListID' => 1,
    'items' => [
        [ 'ip' => '127.0.0.1' ],
        [ 'ip' => '192.168.0.0/16' ]
    ]
]);
?>
appendToGlobalIPList
Update the global IP list, which will not overwrite the original data.
$ok = appendToGlobalIPList($opts)
Description of object $opts:
| Key name | Type | Required | Description | 
|---|---|---|---|
| globalIPListID | number | yes | ID of the IP list | 
| items | array | yes | $itemarray list | 
Description of object $item:
| Key name | Type | Required | Description | 
|---|---|---|---|
| ip | string | no | one IP Address or one CIDR IP | 
Example:
<?php
require_once(__DIR__ . '/vendor/autoload.php');
use OpenResty\Edge2Client;
// use username and password
$client = new Edge2Client([
   'edge_admin_addr' => 'https://admin.openresty.com',
   'username' => 'admin',
   'password' => '123456'
]);
$ok = $client->login();
$ok = $client->appendToGlobalIPList([
    'globalIPListID' => 1,
    'items' => [
        [ 'ip' => '127.0.0.3' ],
    ]
]);
?>
removeFromGlobalIPList
Remove IPs from global IP list, which will not overwrite the original data.
$ok = removeFromGlobalIPList($opts)
Description of object $opts:
| Key name | Type | Required | Description | 
|---|---|---|---|
| globalIPListID | number | yes | ID of the IP list | 
| items | array | yes | $itemarray list | 
Description of object $item:
| Key name | Type | Required | Description | 
|---|---|---|---|
| ip | string | no | one IP Address or one CIDR IP | 
Example:
<?php
require_once(__DIR__ . '/vendor/autoload.php');
use OpenResty\Edge2Client;
// use username and password
$client = new Edge2Client([
   'edge_admin_addr' => 'https://admin.openresty.com',
   'username' => 'admin',
   'password' => '123456'
]);
$ok = $client->login();
$ok = $client->removeFromGlobalIPList([
    'globalIPListID' => 1,
    'items' => [
        [ 'ip' => '127.0.0.3' ],
    ]
]);
?>
getGlobalIPList
$data = getGlobalIPList($globalIPListID)
Example:
<?php
require_once(__DIR__ . '/vendor/autoload.php');
use OpenResty\Edge2Client;
$client = new Edge2Client([
   'edge_admin_addr' => 'https://admin.openresty.com',
   'username' => 'admin',
   'password' => '123456'
]);
$ok = $client->login();
$ipList = $client->getGlobalIPList($globalIPListID);
?>
getAllGlobalIPList
$data = getAllGlobalIPList()
Example:
<?php
require_once(__DIR__ . '/vendor/autoload.php');
use OpenResty\Edge2Client;
$client = new Edge2Client([
   'edge_admin_addr' => 'https://admin.openresty.com',
   'username' => 'admin',
   'password' => '123456'
]);
$ok = $client->login();
$ipList = $client->getAllGlobalIPList();
?>
convCrlToLuaModule
$data = convCrlToLuaModule($crlFiles)
Example:
<?php
require_once(__DIR__ . '/vendor/autoload.php');
use OpenResty\Edge2Client;
$client = new Edge2Client([
   'edge_admin_addr' => 'https://admin.openresty.com',
   'username' => 'admin',
   'password' => '123456'
]);
$crlFiles = array('test.crl');
$ok = $client->login();
$code = $client->convCrlToLuaModule($crlFiles)
?>