{"id":26234786,"url":"https://github.com/lizhichao/one-ck","last_synced_at":"2025-04-09T15:06:55.727Z","repository":{"id":43262941,"uuid":"292736703","full_name":"lizhichao/one-ck","owner":"lizhichao","description":"php tcp client for clickhouse","archived":false,"fork":false,"pushed_at":"2024-09-09T12:05:21.000Z","size":105,"stargazers_count":73,"open_issues_count":2,"forks_count":12,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-04-09T15:06:49.985Z","etag":null,"topics":["clickhouse","clickhouse-client","php","php-clickhouse","php-tcp-client","tcp-client"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lizhichao.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"custom":["https://www.vicsdf.com/img/z.jpg","https://www.vicsdf.com/img/w.jpg"]}},"created_at":"2020-09-04T03:11:51.000Z","updated_at":"2024-12-23T06:35:33.000Z","dependencies_parsed_at":"2023-11-06T09:26:36.616Z","dependency_job_id":"a0ccd6dc-250f-4fd3-890b-56d3c55b6691","html_url":"https://github.com/lizhichao/one-ck","commit_stats":{"total_commits":92,"total_committers":3,"mean_commits":"30.666666666666668","dds":"0.17391304347826086","last_synced_commit":"b6a74bf4bcf7e018ef503c55196f69e5fce2fedd"},"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lizhichao%2Fone-ck","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lizhichao%2Fone-ck/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lizhichao%2Fone-ck/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lizhichao%2Fone-ck/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lizhichao","download_url":"https://codeload.github.com/lizhichao/one-ck/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248055284,"owners_count":21040157,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["clickhouse","clickhouse-client","php","php-clickhouse","php-tcp-client","tcp-client"],"created_at":"2025-03-13T02:28:47.885Z","updated_at":"2025-04-09T15:06:55.705Z","avatar_url":"https://github.com/lizhichao.png","language":"PHP","funding_links":["https://www.vicsdf.com/img/z.jpg","https://www.vicsdf.com/img/w.jpg"],"categories":[],"sub_categories":[],"readme":"## 一个php实现的clickhouse tcp协议客户端 | php tcp client for clickhouse\n\n- 支持流式写入  Support streaming writing\n- 超高的性能，支持1000w/s的写入速度 Super high performance, Support 1000w/s writing speed\n- tcp对服务器对服务器友好，压力小 tcp is server-friendly, with little pressure\n- 零依赖 Zero dependence\n\n### 安装 | install\n\n`composer require lizhichao/one-ck`\n\n\u003e `php5.6 - php7.1` 不支持 `Decimal128` ，请使用 `0.1.x` 版本   \n\u003e `php7.2 \u003e= ` 推荐使用 `0.2.x`版本   \n\u003e clickhouse QQ交流群 970435787\n\n\n### 支持的数据类型 | Supported types \n- [x] UInt8, UInt16, UInt32, UInt64, Int8, Int16, Int32, Int64\n- [x] Float32, Float64\n- [x] Decimal(P, S), Decimal32(S), Decimal64(S), Decimal128(S)\n- [x] String\n- [x] Nothing\n- [x] FixedString(N)\n- [x] UUID \n- [x] Date\n- [x] Datetime\n- [x] Datetime64\n- [x] Nullable(T)\n- [x] IPv4\n- [x] IPv6\n- [x] Array(T)\n- [x] SimpleAggregateFunction(F, T)\n- [ ] Tuple(T)\n- [ ] Int128,Int256,UInt128,UInt256,Decimal256(S)\n- [ ] Bool\n- [ ] JSON\n- [ ] Enum (can use `LowCardinality` instead)\n\n### Array of client options\n\nIt is also possible to create the client with configuration options:\n\n```php\nuse OneCk\\Client;\n\n$client = new Client(\n    'tcp://localhost:9000',\n    'username',\n    'password',\n    'database',\n    [\n        'connect_timeout' =\u003e 3,\n        'socket_timeout'  =\u003e 30,\n        'tcp_nodelay'     =\u003e true,\n        'persistent'      =\u003e true,\n    ]\n);\n```\n\nThe following options are available:\n\nName | Type | Default | Description\n--- | :---: | :---: | ---\n*connect_timeout* | float | 3.0 | The number of seconds that the client waits for a connect to a ClickHouse server before throwing a `CkException` exception.\n*socket_timeout* | float | 30.0 | The number of seconds that the client waits for a respond from a ClickHouse server before throwing a `CkException` exception.\n*tcp_nodelay* | boolean | false | Whether the Nagle algorithm is disabled on a TCP connection.\n*persistent* | boolean | false | Whether to use a persistent connection.\n\n### 使用例子 | Demo\n```php\nuse OneCk\\Client;\nuse OneCk\\Types;\n//default\n//$ck = new Client('tcp://127.0.0.1:9000');\n\n$t1 = microtime(true);\n$ck = new Client('tcp://192.168.31.216:9091', 'default', '123456', 'test1');\n\n$data['server info']  = $ck-\u003egetServerInfo();\n$data['drop table']   = $ck-\u003equery('DROP TABLE IF EXISTS t6');\n$table                = [\n    'CREATE TABLE t6 (',\n    '`id` UInt32,',\n    '`f1` Int32,',\n    '`f2` Nullable(Int32),',\n    '`f3` UInt8,',\n    '`f4` Nullable(UInt8),',\n    '`f5` UInt16,',\n    '`f6` UInt64,',\n    '`f7` Int64,',\n    '`f8` Float32,',\n    '`f9` Float64,',\n    '`f10` Nullable(Float64),',\n    '`f11` Decimal32(3),',\n    '`f12` Decimal64(5),',\n    '`f13` Decimal128(7),',\n    '`f14` Nullable(Decimal128(7)),',\n    '`f15` String,',\n    '`f16` Nullable(String),',\n    '`f17` FixedString(32),',\n    '`f18` UUID,',\n    '`f19` Date,',\n    '`f20` Nullable(Date),',\n    '`f21` Datetime,',\n    '`f22` Datetime64(3),',\n    '`f23` IPv4,',\n    '`f24` Nullable(IPv4),',\n    '`f25` IPv6,',\n    '`f26` LowCardinality(String),',\n    '`f27` Array(Int32),',\n    '`f28` Array(Array(Array(Nullable(Date)))),',\n    '`f29` Array(Array(Array(Array(Array(Nullable(Datetime))))))',\n    ') ENGINE = MergeTree() ORDER BY id SETTINGS index_granularity = 8192'\n];\n$data['create table'] = $ck-\u003equery(implode(\"\\n\", $table));\n\n$data['insert data'] = $ck-\u003einsert('t6', [\n    [\n        'id'  =\u003e 1,\n        'f1'  =\u003e -3,\n        'f2'  =\u003e null,\n        'f3'  =\u003e 127,\n        'f4'  =\u003e null,\n        'f5'  =\u003e 3322,\n        'f6'  =\u003e 1844674407370955161,\n        'f7'  =\u003e 9223372036854775807,\n        'f8'  =\u003e -2132121.5,\n        'f9'  =\u003e 6546546544665.66658,\n        'f10' =\u003e null,\n        'f11' =\u003e 552.339,\n        'f12' =\u003e 3658.6954,\n        'f13' =\u003e '170141183460469231168730371588.4105721',\n        'f14' =\u003e null,\n        'f15' =\u003e 'emoji😀😁😂😃😄',\n        'f16' =\u003e null,\n        'f17' =\u003e md5('a'),\n        'f18' =\u003e '016e64be-605f-4108-8a67-495d74d7ef3c',\n        'f19' =\u003e '2020-09-05',\n        'f20' =\u003e null,\n        'f21' =\u003e '2020-09-05 14:25:12',\n        'f22' =\u003e '2020-09-05 14:25:12.258',\n        'f23' =\u003e '192.168.1.1',\n        'f24' =\u003e null,\n        'f25' =\u003e 'CDCD:910A:2222:5498:8475:1111:3900:2020',\n        'f26' =\u003e 'eee',\n        'f27' =\u003e [0, -2, 3, 4, 5, 6, 7, 8, 64],\n        'f28' =\u003e [[['2020-01-05', null, '2020-01-06']], [['2020-01-07'], ['2020-01-08']], [['2020-01-09']]],\n        'f29' =\u003e [[[[[\"2020-01-05 05:05:05\", null, \"2020-01-06 15:16:17\"]], [[\"2020-01-07 18:19:20\"], [\"2020-01-08 21:22:23\"]], [[\"2020-01-09 00:00:00\"]]], [[[\"2020-01-10 01:00:00\", null]]]], [[[[\"2020-01-11 00:00:01\", null, \"2020-01-12 11:01:58\"]], [[\"2020-01-13 21:22:01\"]]]]]\n    ],\n    [\n        'id'  =\u003e 2,\n        'f1'  =\u003e 3,\n        'f2'  =\u003e 3,\n        'f3'  =\u003e 3,\n        'f4'  =\u003e 3,\n        'f5'  =\u003e 3,\n        'f6'  =\u003e 3,\n        'f7'  =\u003e 3,\n        'f8'  =\u003e 3,\n        'f9'  =\u003e 3,\n        'f10' =\u003e 3,\n        'f11' =\u003e -552.339,\n        'f12' =\u003e -3658.6954,\n        'f13' =\u003e '-170141183460469231168730371588.4105721',\n        'f14' =\u003e 3,\n        'f15' =\u003e str_repeat(md5('aa'), '6'),\n        'f16' =\u003e '',\n        'f17' =\u003e md5('55'),\n        'f18' =\u003e md5('55'),\n        'f19' =\u003e '2020-09-06',\n        'f20' =\u003e '2020-09-06',\n        'f21' =\u003e '2020-09-06 14:25:12',\n        'f22' =\u003e '2020-09-06 14:25:12.258',\n        'f23' =\u003e '251.222.221.231',\n        'f24' =\u003e '192.168.1.2',\n        'f25' =\u003e '1030::C9B4:FF12:48AA:1A2B',\n        'f26' =\u003e 'eee22',\n        'f27' =\u003e [1, 2, 3, 4],\n        'f28' =\u003e [[['2020-01-05', '2020-01-06']], [['2020-01-07', null], ['2020-01-08']], [['2020-01-09']]],\n        'f29' =\u003e [[[[[null]]]]]\n    ],\n    [\n        'id'  =\u003e 3,\n        'f1'  =\u003e -1,\n        'f2'  =\u003e 3,\n        'f3'  =\u003e 3,\n        'f4'  =\u003e 3,\n        'f5'  =\u003e 3,\n        'f6'  =\u003e 3,\n        'f7'  =\u003e 3,\n        'f8'  =\u003e 3,\n        'f9'  =\u003e 3,\n        'f10' =\u003e 3,\n        'f11' =\u003e 3,\n        'f12' =\u003e 3,\n        'f13' =\u003e 3,\n        'f14' =\u003e 3,\n        'f15' =\u003e 'aaa',\n        'f16' =\u003e 'aaa',\n        'f17' =\u003e md5('a'),\n        'f18' =\u003e '3026ee79-ac2a-46d2-882d-959a55d71025',\n        'f19' =\u003e '2020-09-07',\n        'f20' =\u003e '2020-09-07',\n        'f21' =\u003e '2020-09-07 14:25:12',\n        'f22' =\u003e '2020-09-07 14:25:12.258',\n        'f23' =\u003e '192.168.1.1',\n        'f24' =\u003e null,\n        'f25' =\u003e '2001:DB8:2de::e13',\n        'f26' =\u003e 'eee22',\n        'f27' =\u003e [12344],\n        'f28' =\u003e [[['2020-01-05', '2020-01-06'], [null]], [['2020-01-07'], ['2020-01-08']], [['2020-01-09']]],\n        'f29' =\u003e [[[[['2018-01-25 11:25:14']]]]]\n    ]\n]);\n\n\n//$data['struct'] = $ck-\u003equery('desc t6');\n\n\n$data['select t6'] = $ck-\u003equery('select * from t6');\n\n$data['select t6 int64'] = $ck-\u003equery(\"select id,f6 from t6 where f6=1844674407370955161\");\n\n$data['select t6 Decimal32'] = $ck-\u003equery(\"select id,f11 from t6 where f11='552.339'\");\n\n$data['select t6 Decimal64'] = $ck-\u003equery(\"select id,f12 from t6 where f12='-3658.69540'\");\n\n$data['select t6 Decimal128'] = $ck-\u003equery(\"select id,f13 from t6 where f13='170141183460469231168730371588.4105721'\");\n\n$data['select t6 uuid'] = $ck-\u003equery(\"select id,f18 from t6 where f18='3026ee79-ac2a-46d2-882d-959a55d71025'\");\n\n$data['select t6 date'] = $ck-\u003equery(\"select id,f19 from t6 where f19='2020-09-05'\");\n\n$data['select t6 datetime'] = $ck-\u003equery(\"select id,f21 from t6 where f21='2020-09-07 20:25:12'\");\n\n$data['select t6 datetime64'] = $ck-\u003equery(\"select id,f22 from t6 where f22='2020-09-06 20:25:12.258'\");\n\n$data['select t6 ip'] = $ck-\u003equery(\"select id,f23,f25 from t6 where f23=\" . Types::encodeIpv4('192.168.1.1'));\n\n$data['select t6 ip64'] = $ck-\u003equery(\"select id,f23,f25 from t6 where f25='\" . Types::encodeIpv6('1030::c9b4:ff12:48aa:1a2b') . \"'\");\n\n$data['nothing'] = $ck-\u003equery('select array()');\n\n\n\n// flow of  write\n$data['drop table'] = $ck-\u003equery('DROP TABLE IF EXISTS t7');\n$table                = [\n    'CREATE TABLE t7 (',\n    '`id` UInt32,',\n    '`f2` Nullable(Int32),',\n    '`f5` UInt16,',\n    '`f15` String',\n    ') ENGINE = MergeTree() ORDER BY id SETTINGS index_granularity = 8192'\n];\n$data['create table'] = $ck-\u003equery(implode(\"\\n\", $table));\n$ck-\u003ewriteStart('t7',['id','f2','f5','f15']);\nfor ($i = 0; $i \u003c 100; $i++) {\n    $da = [];\n    for ($j = 0; $j \u003c 1000; $j++) {\n        $da[] = [\n            'id' =\u003e mt_rand(1,1000000),\n            'f2' =\u003e mt_rand(-1000000,1000000),\n            'f5' =\u003e mt_rand(1,10000),\n            'f15' =\u003e md5(mt_rand(1,10000))\n        ];\n    }\n    $ck-\u003ewriteBlock($da);\n}\n\n$ck-\u003ewriteEnd();\n\n$data['write 10w rows time'] = microtime(true) - $t1;\n\necho json_encode($data);\n\n//Close connection\nunset($ck);\n```\n\n## 我的其他仓库\n\n* [一个极简高性能php框架，支持[swoole | php-fpm ]环境](https://github.com/lizhichao/one)\n* [国密sm3 sm4库](https://github.com/lizhichao/sm)\n* [中文分词](https://github.com/lizhichao/VicWord)\n* [nsq客户端](https://github.com/lizhichao/one-nsq)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flizhichao%2Fone-ck","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flizhichao%2Fone-ck","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flizhichao%2Fone-ck/lists"}