Nacos-Sdk-PHP for PHP client allows you to access Nacos OpenAPI. Open API Guide
composer require tinywan/nacos-sdk-php
use Nacos\NacosClient;
$client = new NacosClient('localhost', 8848);
$dataId = 'database.php';
$group = 'DEFAULT_GROUP';
$result = $client->getConfig($dataId, $group);
if nacos.core.auth.enabled=false
use Nacos\NacosClient;
use Nacos\NacosAuth;
$client = new NacosClient('localhost', 8848);
$auth = new NacosAuth($client);
$auth->login('nacos','nacos');
$dataId = 'database.php';
$group = 'DEFAULT_GROUP';
$result = $client->getConfig($dataId, $group);
use Nacos\NacosClient;
$dataId = 'database.php';
$group = 'DEFAULT_GROUP';
$namespace = 'c78ce19d-82d1-456a-8552-9a0db6c11d01';
$client = new NacosClient('localhost', 8848);
$client->setNamespace($namespace);
$result = $client->getConfig($dataId, $group);
use Nacos\NacosClient;
use Nacos\Models\Config;
$dataId = 'database.php';
$group = 'DEFAULT_GROUP';
$namespace = 'c78ce19d-82d1-456a-8552-9a0db6c11d01';
$client = new NacosClient('localhost', 8848);
$client->setNamespace($namespace);
$client->setTimeout(3);
$content = $client->getConfig($dataId, $group);
$contentMd5 = md5($content);
$cache = new Config();
$cache->dataId = $dataId;
$cache->group = $group;
$cache->namespace = $namespace;
$cache->contentMd5 = $contentMd5;
$result = $client->listenConfig([$cache]);
if(!empty($result)) {
$updateContent = $client->getConfig($dataId, $group);
echo '[x] update content : ' . $updateContent, "\n";
} else {
echo '[x] this is not update ', "\n";
}
use Nacos\NacosClient;
use Nacos\Models\Config;
$client = new NacosClient('localhost', 8848);
$serviceName = 'NacosTaskService';
$instance = new ServiceInstance();
$instance->serviceName = $serviceName;
$instance->ip = '127.0.0.1';
$instance->port = 80;
$instance->healthy = true;
$instance->ephemeral = false;
$isSuccess = $client->createInstance($instance);
if(true === $isSuccess) {
echo '[x] create service instance success ', "\n";
} else {
echo '[x] create service instance fail ', "\n";
}
setNamespace
setTimeout
getConfig
publishConfig
removeConfig
listenConfig
createInstance
deleteInstance
updateInstance
getInstanceList
getInstance
sendInstanceBeat
NacosClientTest
./vendor/bin/phpunit --bootstrap src/Nacos/NacosClient.php tests/NacosClientTest.php
NacosConfig
./vendor/bin/phpunit --bootstrap src/Nacos/NacosConfig.php tests/NacosConfigTest.php
NacosNaming
./vendor/bin/phpunit --bootstrap src/Nacos/NacosNaming.php tests/NacosNamingTest.php
Docker Composer
docker run --rm --interactive --tty -v e:/GitHub/nacos-sdk-php:/app composer:1.10.16 install --ignore-platform-reqs
Git Tag
git push origin v0.0.42
// or push all
git push origin --tags