承接 ierusalim/php-clickhouse 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

ierusalim/php-clickhouse

Composer 安装命令:

composer require ierusalim/php-clickhouse

包简介

ClickHouse simple access library (http, https)

README 文档

README

Build Status codecov

ClickHouse simple access library (http, https)

Class ClickHouseAPI

Class ClickHouseAPI contains simple http/https connector for ClickHouse server and have not dependencies (may be used independently, file src/ClichHouseAPI.php).

API simple requests functions:

  • query($sql [,$post_data]) - object-oriented style SQL-query (return $this, throw exceptions)
  • getQuery($h_query [, $sess]) - send GET request
  • postQuery($h_query, $post_data [, $sess]) - send POST request

Async (parallel) requests:

  • Set toSlot(name) before any request, and the request will be launched asynchronously.
  • toSlot("name")->query($sql) - start async-$sql-query, results will be written to slot "name"
  • Get results from this slot may at any time later:
  • slotResults("name") - get results from slot "name".

Server-state functions:

  • setServerUrl($url) - set ClickHouse server parameters by url (host, port, etc.)
  • getVersion() - return version of ClickHouse server (side effect - detect server features)
  • isSupported(feature-name) - true or false depending on the server support features.
Sessions:
  • getSession() - get current session_id from options
  • setSession([$sess]) - set session_id or generate new session_id and set it
Options:
  • setOption($key, $value) - set http-option for all next requests
  • getOption($key) - get current http-option value
  • delOption($key) - delete http-option (same ->setOption($key, null)

Class ClickHouseQuery

Class ClickHouseQuery contains wrapper for ClickHouseAPI and allow to easily send queries to ClickHouse server and parsing answering data.

Main query-functions for use:

  • queryFalse($sql, [post])- for queries that should not return anything. False if ok, or error string.
  • queryTrue($sql, [post]) - return false only if error, otherwise return true or response data.
  • queryValue($sql, [post]) - send any query and receive all data in one string (false if error)
  • queryArray($sql) - for queries returning structured data (usually one or more table rows)
  • queryKeyValues(see descr.) - for queries returning 2 columns, first means as key, second as value
  • queryInsertArray($table, $fields_names, $fields_set) - insert data into table from array
  • queryInsertFile($table, $file, $structure) - insert data from file into table
  • queryInsertGzip($table, $file, $format [, $fields]) - insert data from file, using gzip when sending

Class ClickHouseFunctions

Class ClickHouseFunctions based on ClickHouseQuery and ClickHouseAPI and contains functions for simple operations with ClickHouse.

Functions:

  • createTableQuick($table, $fields_arr) - create table with specified fields
  • sendFileInsert($file, $table) - send TabSeparated-file into table (structure autodetect)
  • clearTable($table [, $sess]) - clear table (DROP and re-create)
  • dropTable($table [, $sess]) - drop specified table
  • renameTable($from_name_or_arr [, $to_name] [, $sess]) - rename tables
  • getTableFields($table, ...) - returns [field_name=>field_type] array
  • getTableInfo($table [, $extended]) - returns array with info about table
  • getTablesList([$db] [,$pattern]) - returns tables list by SHOW TABLES request
  • createDatabase($db) - create new database with specified name
  • dropDatabase($db) - drop specified database and remove all tables inside
  • getDatabasesList() - returns array contained names of existing Databases
  • setCurrentDatabase($db [, $sess]) - set current database by 'USE db' request or by option
  • getCurrentDatabase([$sess]) - return results of 'SELECT currentDatabase()' or from option
  • getUptime() - return server uptime in seconds
  • getSystemSettings() - get information from system.settings as array [name=>value]

Example:

<?php
    namespace ierusalim\ClickHouse;

    require "vendor/autoload.php";

    $ch = new ClickHouseFunctions("http://127.0.0.1:8123/");

    echo "ClickHouse version: " . $ch->getVersion();
    if (!$ch->isSupported('query')) {
        die(" Server not ready");
    }
    echo " Server uptime: " . $ch->getUptime();
    
    echo "\n\nDatabases: ";
    print_r($ch->getDatabasesList());

    $ch->setCurrentDatabase("system");
    echo "Tables in '" . $ch->getCurrentDatabase() ."' database:\n";
    print_r($ch->getTablesList());

    $ch->setCurrentDatabase("default");

    $ch->createTableQuick("temptab", [
        'id'   => 'integer',
        'dt' => 'date now()',
        'name' => "char(32) 'example'",
        'email'  => 'string'
    ]);
    
    $ch->queryInsertArray("temptab", null, [
        'id' => 1,
        'email' => 'noreply@github.com'
    ]);
    
    $ch->queryInsertArray("temptab", ['id', 'email', 'name'], [
        [2, 'reply@github.com', 'Andy'],
        [3, null , 'Donald'],
    ]);

    $ch->queryInsertArray("temptab", null, [
        ['id'=>4, 'name'=>'Ronald', 'email'=>'no'],
        ['id'=>5, 'name'=>'', 'email'=>'yes'],
    ]);
    
    $rows = $ch->queryArray("SELECT * FROM temptab");
    print_r($rows);
    
    $name_emails_arr = $ch->queryKeyValues('temptab', 'name, email');
    print_r($name_emails_arr);
    
    print_r($ch->getTableInfo("temptab"));

ierusalim/php-clickhouse 适用场景与选型建议

ierusalim/php-clickhouse 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3.38k 次下载、GitHub Stars 达 6, 最近一次更新时间为 2017 年 07 月 21 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「database」 「client」 「driver」 「clickhouse」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 ierusalim/php-clickhouse 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 ierusalim/php-clickhouse 我们能提供哪些服务?
定制开发 / 二次开发

基于 ierusalim/php-clickhouse 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 3.38k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 6
  • 点击次数: 11
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 6
  • Watchers: 2
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: Apache-2.0
  • 更新时间: 2017-07-21