PHP code example of opensearch-dev / opensearch

1. Go to this page and download the library: Download opensearch-dev/opensearch library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

opensearch-dev / opensearch example snippets


go(function() {

    $coClient = new OpenSearch\Client\OpenSearchClient('some-key', 'some-secret',
            'http://opensearch-cn-hangzhou.aliyuncs.com');
    $coClient->setHttpHandler(new OpenSearch\Client\Handler\SwooleHttpHandler()); // 更换请求处理器

    $resultObj = $coClient->get('/apps');
    $resultJSON = $resultObj->result;
    $result = json_decode($resultJSON, true);
    fprintf(STDOUT, "name=%s" . PHP_EOL, $result['result']['name']);

});