Completed
Branch master (48dd8f)
by Igor
05:34 queued 02:55
created
example/cluster/cluster_02_create.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -11,12 +11,12 @@
 block discarded – undo
11 11
 $cl->setScanTimeOut(2.5); // 2500 ms
12 12
 if (!$cl->isReplicasIsOk())
13 13
 {
14
-    throw new Exception('Replica state is bad , error='.$cl->getError());
14
+    throw new Exception('Replica state is bad , error=' . $cl->getError());
15 15
 }
16 16
 //
17
-$cluster_name='sharovara';
17
+$cluster_name = 'sharovara';
18 18
 //
19
-echo "> $cluster_name , count shard   = ".$cl->getClusterCountShard($cluster_name)." ; count replica = ".$cl->getClusterCountReplica($cluster_name)."\n";
19
+echo "> $cluster_name , count shard   = " . $cl->getClusterCountShard($cluster_name) . " ; count replica = " . $cl->getClusterCountReplica($cluster_name) . "\n";
20 20
 
21 21
 
22 22
 
Please login to merge, or discard this patch.
example/cluster/cluster_03_list.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -10,15 +10,15 @@
 block discarded – undo
10 10
 
11 11
 if (!$cl->isReplicasIsOk())
12 12
 {
13
-    throw new Exception('Replica state is bad , error='.$cl->getError());
13
+    throw new Exception('Replica state is bad , error=' . $cl->getError());
14 14
 }
15
-$cluster_name='sharovara';
15
+$cluster_name = 'sharovara';
16 16
 
17
-echo "> $cluster_name , count shard   = ".$cl->getClusterCountShard($cluster_name)." ; count replica = ".$cl->getClusterCountReplica($cluster_name)."\n";
17
+echo "> $cluster_name , count shard   = " . $cl->getClusterCountShard($cluster_name) . " ; count replica = " . $cl->getClusterCountReplica($cluster_name) . "\n";
18 18
 
19 19
 
20 20
 // ------------------------------------------------------------------------------------------------------------------------------------------------------------------------
21
-$nodes=$cl->getNodesByTable('shara.adpreview_body_views_sharded');
21
+$nodes = $cl->getNodesByTable('shara.adpreview_body_views_sharded');
22 22
 
23 23
 foreach ($nodes as $node)
24 24
 {
Please login to merge, or discard this patch.
example/cluster/cluster_06_truncate_table.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -12,27 +12,27 @@
 block discarded – undo
12 12
 $cl->setSoftCheck(true);
13 13
 if (!$cl->isReplicasIsOk())
14 14
 {
15
-    throw new Exception('Replica state is bad , error='.$cl->getError());
15
+    throw new Exception('Replica state is bad , error=' . $cl->getError());
16 16
 }
17 17
 
18 18
 
19
-$tables=$cl->getTables();
19
+$tables = $cl->getTables();
20 20
 
21 21
 foreach ($tables as $dbtable=>$tmp)
22 22
 {
23 23
     echo ">>> $dbtable :";
24 24
 
25
-    $size=$cl->getSizeTable($dbtable);
25
+    $size = $cl->getSizeTable($dbtable);
26 26
 
27 27
 
28
-    echo "\t".humanFileSize($size)."\n";
28
+    echo "\t" . humanFileSize($size) . "\n";
29 29
 
30 30
 }
31 31
 
32 32
 
33
-$table_for_truncate='target.events_sharded';
33
+$table_for_truncate = 'target.events_sharded';
34 34
 
35
-$result=$cl->truncateTable($table_for_truncate);
35
+$result = $cl->truncateTable($table_for_truncate);
36 36
 
37 37
 echo "Result:truncate table\n";
38 38
 print_r($result);
Please login to merge, or discard this patch.
example/cluster/cluster_07_test_ddl.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -7,13 +7,13 @@  discard block
 block discarded – undo
7 7
 
8 8
 
9 9
 
10
-$cl = new ClickHouseDB\Cluster(['host'=>'172.18.0.8','username'=>'default','password'=>'','port'=>8123]);
10
+$cl = new ClickHouseDB\Cluster(['host'=>'172.18.0.8', 'username'=>'default', 'password'=>'', 'port'=>8123]);
11 11
 
12 12
 $cl->setScanTimeOut(2.5); // 2500 ms
13 13
 $cl->setSoftCheck(true);
14 14
 if (!$cl->isReplicasIsOk())
15 15
 {
16
-    throw new Exception('Replica state is bad , error='.$cl->getError());
16
+    throw new Exception('Replica state is bad , error=' . $cl->getError());
17 17
 }
18 18
 
19 19
 print_r($cl->getClusterList());
@@ -25,10 +25,10 @@  discard block
 block discarded – undo
25 25
 
26 26
 
27 27
 $cl->activeClient()->setTimeout(0.01);
28
-for ($z=0;$z<50;$z++)
28
+for ($z = 0; $z < 50; $z++)
29 29
 {
30
-    try{
31
-        $x=$cl->activeClient()->write("DROP TABLE IF EXISTS default.asdasdasd ON CLUSTER cluster2");
30
+    try {
31
+        $x = $cl->activeClient()->write("DROP TABLE IF EXISTS default.asdasdasd ON CLUSTER cluster2");
32 32
     }catch (Exception $exception)
33 33
     {
34 34
 
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
 }
37 37
 
38 38
 $cl->activeClient()->setTimeout(22);
39
-$x=$cl->activeClient()->write("DROP TABLE IF EXISTS default.asdasdasd ON CLUSTER cluster2");
39
+$x = $cl->activeClient()->write("DROP TABLE IF EXISTS default.asdasdasd ON CLUSTER cluster2");
40 40
 $x->dump();
41 41
 
42 42
 
Please login to merge, or discard this patch.
example/cluster/cluster_05_select_node.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -12,16 +12,16 @@
 block discarded – undo
12 12
 $cl->setSoftCheck(true);
13 13
 if (!$cl->isReplicasIsOk())
14 14
 {
15
-    throw new Exception('Replica state is bad , error='.$cl->getError());
15
+    throw new Exception('Replica state is bad , error=' . $cl->getError());
16 16
 }
17 17
 //
18
-$cluster_name='sharovara';
18
+$cluster_name = 'sharovara';
19 19
 //
20
-echo "> $cluster_name , count shard   = ".$cl->getClusterCountShard($cluster_name)." ; count replica = ".$cl->getClusterCountReplica($cluster_name)."\n";
20
+echo "> $cluster_name , count shard   = " . $cl->getClusterCountShard($cluster_name) . " ; count replica = " . $cl->getClusterCountReplica($cluster_name) . "\n";
21 21
 
22 22
 
23 23
 // Выбрать IP содержащий строку ".248" типа 123.123.123.248, разделитель ; - если не найдена первая берется
24
-$cli=$cl->clientLike($cluster_name,'.298;.964');
24
+$cli = $cl->clientLike($cluster_name, '.298;.964');
25 25
 $cli->ping();
26 26
 echo "\n----\nEND\n";
27 27
 // ----------------------------------------------------------------------
Please login to merge, or discard this patch.
example/cluster/cluster_01_start.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -10,7 +10,7 @@  discard block
 block discarded – undo
10 10
 $cl->setScanTimeOut(2.5); // 2500 ms
11 11
 if (!$cl->isReplicasIsOk())
12 12
 {
13
-    throw new Exception('Replica state is bad , error='.$cl->getError());
13
+    throw new Exception('Replica state is bad , error=' . $cl->getError());
14 14
 }
15 15
 
16 16
 echo "Ips:\n";
@@ -19,13 +19,13 @@  discard block
 block discarded – undo
19 19
 print_r($cl->getClusterList());
20 20
 
21 21
 //
22
-foreach (['pulse','repikator','sharovara','repikator3x','sharovara3x'] as $name)
22
+foreach (['pulse', 'repikator', 'sharovara', 'repikator3x', 'sharovara3x'] as $name)
23 23
 {
24 24
     echo "-------------------- $name ---------------------------\n";
25 25
     print_r($cl->getClusterNodes($name));
26 26
 
27
-    echo "> Count Shard   = ".$cl->getClusterCountShard($name)."\n";
28
-    echo "> Count Replica = ".$cl->getClusterCountReplica($name)."\n";
27
+    echo "> Count Shard   = " . $cl->getClusterCountShard($name) . "\n";
28
+    echo "> Count Replica = " . $cl->getClusterCountReplica($name) . "\n";
29 29
 }
30 30
 // ----------------------------------------------------------------------
31 31
 echo "\n----\nEND\n";
Please login to merge, or discard this patch.
example/exam12_array.php 1 patch
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
 
52 52
 
53 53
 echo "\ntestRFCCSVWrite>>>>\n";
54
-$fileName='/tmp/testRFCCSVWrite.CSV';
54
+$fileName = '/tmp/testRFCCSVWrite.CSV';
55 55
 date_default_timezone_set('Europe/Moscow');
56 56
 $db->write("DROP TABLE IF EXISTS testRFCCSVWrite");
57 57
 $db->write('CREATE TABLE testRFCCSVWrite (
@@ -66,24 +66,24 @@  discard block
 block discarded – undo
66 66
 
67 67
 @unlink($fileName);
68 68
 
69
-$data=[
70
-    ['event_time'=>date('Y-m-d H:i:s'),'strs'=>'SOME STRING','flos'=>1.1,'ints'=>1,'arr1'=>[1,2,3],'arrs'=>["A","B"]],
71
-    ['event_time'=>date('Y-m-d H:i:s'),'strs'=>'SOME STRING','flos'=>2.3,'ints'=>2,'arr1'=>[1,2,3],'arrs'=>["A","B"]],
72
-    ['event_time'=>date('Y-m-d H:i:s'),'strs'=>'SOME\'STRING','flos'=>0,'ints'=>0,'arr1'=>[1,2,3],'arrs'=>["A","B"]],
73
-    ['event_time'=>date('Y-m-d H:i:s'),'strs'=>'SOME\'"TRING','flos'=>0,'ints'=>0,'arr1'=>[1,2,3],'arrs'=>["A","B"]],
74
-    ['event_time'=>date('Y-m-d H:i:s'),'strs'=>"SOMET\nRI\n\"N\"G\\XX_ABCDEFG",'flos'=>0,'ints'=>0,'arr1'=>[1,2,3],'arrs'=>["A","B\nD\nC"]],
75
-    ['event_time'=>date('Y-m-d H:i:s'),'strs'=>"ID_ARRAY",'flos'=>0,'ints'=>0,'arr1'=>[1,2,3],'arrs'=>["A","B\nD\nC"]]
69
+$data = [
70
+    ['event_time'=>date('Y-m-d H:i:s'), 'strs'=>'SOME STRING', 'flos'=>1.1, 'ints'=>1, 'arr1'=>[1, 2, 3], 'arrs'=>["A", "B"]],
71
+    ['event_time'=>date('Y-m-d H:i:s'), 'strs'=>'SOME STRING', 'flos'=>2.3, 'ints'=>2, 'arr1'=>[1, 2, 3], 'arrs'=>["A", "B"]],
72
+    ['event_time'=>date('Y-m-d H:i:s'), 'strs'=>'SOME\'STRING', 'flos'=>0, 'ints'=>0, 'arr1'=>[1, 2, 3], 'arrs'=>["A", "B"]],
73
+    ['event_time'=>date('Y-m-d H:i:s'), 'strs'=>'SOME\'"TRING', 'flos'=>0, 'ints'=>0, 'arr1'=>[1, 2, 3], 'arrs'=>["A", "B"]],
74
+    ['event_time'=>date('Y-m-d H:i:s'), 'strs'=>"SOMET\nRI\n\"N\"G\\XX_ABCDEFG", 'flos'=>0, 'ints'=>0, 'arr1'=>[1, 2, 3], 'arrs'=>["A", "B\nD\nC"]],
75
+    ['event_time'=>date('Y-m-d H:i:s'), 'strs'=>"ID_ARRAY", 'flos'=>0, 'ints'=>0, 'arr1'=>[1, 2, 3], 'arrs'=>["A", "B\nD\nC"]]
76 76
 ];
77 77
 
78 78
 //// 1.1 + 2.3 = 3.3999999761581
79 79
 //
80 80
 foreach ($data as $row)
81 81
 {
82
-    file_put_contents($fileName,\ClickHouseDB\Quote\FormatLine::CSV($row)."\n",FILE_APPEND);
82
+    file_put_contents($fileName, \ClickHouseDB\Quote\FormatLine::CSV($row) . "\n", FILE_APPEND);
83 83
 }
84 84
 //
85 85
 echo "FILE:\n\n";
86
-echo file_get_contents($fileName)."\n\n----\n";
86
+echo file_get_contents($fileName) . "\n\n----\n";
87 87
 
88 88
 //
89 89
 $db->insertBatchFiles('testRFCCSVWrite', [$fileName], [
@@ -95,13 +95,13 @@  discard block
 block discarded – undo
95 95
     'arrs',
96 96
 ]);
97 97
 
98
-$st=$db->select('SELECT * FROM testRFCCSVWrite');
98
+$st = $db->select('SELECT * FROM testRFCCSVWrite');
99 99
 print_r($st->rows());
100 100
 //
101 101
 
102 102
 
103 103
 echo "\n<<<<< TAB >>>>\n";
104
-$fileName='/tmp/testRFCCSVWrite.TAB';@unlink($fileName);
104
+$fileName = '/tmp/testRFCCSVWrite.TAB'; @unlink($fileName);
105 105
 
106 106
 
107 107
 $db->write("DROP TABLE IF EXISTS testTABWrite");
@@ -117,22 +117,22 @@  discard block
 block discarded – undo
117 117
 
118 118
 
119 119
 
120
-$data=[
121
-    ['event_time'=>date('Y-m-d H:i:s'),'strs'=>"STING\t\tSD!\"\nFCD\tSAD\t\nDSF",'flos'=>-2.3,'ints'=>123,'arr1'=>[1,2,3],'arrs'=>["A","B"]],
122
-    ['event_time'=>date('Y-m-d H:i:s'),'strs'=>'SOME\'STRING','flos'=>0,'ints'=>12123,'arr1'=>[1,2,3],'arrs'=>["A","B"]],
123
-    ['event_time'=>date('Y-m-d H:i:s'),'strs'=>'SOME\'"TR\tING','flos'=>0,'ints'=>0,'arr1'=>[1,2,3],'arrs'=>["A","B"]],
124
-    ['event_time'=>date('Y-m-d H:i:s'),'strs'=>"SOMET\nRI\n\"N\"G\\XX_ABCDEFG",'flos'=>0,'ints'=>1,'arr1'=>[1,2,3],'arrs'=>["A","B\nD\ns\tC"]],
125
-    ['event_time'=>date('Y-m-d H:i:s'),'strs'=>"ID_ARRAY",'flos'=>-2.3,'ints'=>-12123,'arr1'=>[1,2,3],'arrs'=>["A","B\nD\nC\n\t\n\tTABARRAYS"]]
120
+$data = [
121
+    ['event_time'=>date('Y-m-d H:i:s'), 'strs'=>"STING\t\tSD!\"\nFCD\tSAD\t\nDSF", 'flos'=>-2.3, 'ints'=>123, 'arr1'=>[1, 2, 3], 'arrs'=>["A", "B"]],
122
+    ['event_time'=>date('Y-m-d H:i:s'), 'strs'=>'SOME\'STRING', 'flos'=>0, 'ints'=>12123, 'arr1'=>[1, 2, 3], 'arrs'=>["A", "B"]],
123
+    ['event_time'=>date('Y-m-d H:i:s'), 'strs'=>'SOME\'"TR\tING', 'flos'=>0, 'ints'=>0, 'arr1'=>[1, 2, 3], 'arrs'=>["A", "B"]],
124
+    ['event_time'=>date('Y-m-d H:i:s'), 'strs'=>"SOMET\nRI\n\"N\"G\\XX_ABCDEFG", 'flos'=>0, 'ints'=>1, 'arr1'=>[1, 2, 3], 'arrs'=>["A", "B\nD\ns\tC"]],
125
+    ['event_time'=>date('Y-m-d H:i:s'), 'strs'=>"ID_ARRAY", 'flos'=>-2.3, 'ints'=>-12123, 'arr1'=>[1, 2, 3], 'arrs'=>["A", "B\nD\nC\n\t\n\tTABARRAYS"]]
126 126
 ];
127 127
 
128 128
 
129 129
 foreach ($data as $row)
130 130
 {
131
-    file_put_contents($fileName,\ClickHouseDB\Quote\FormatLine::TSV($row)."\n",FILE_APPEND);
131
+    file_put_contents($fileName, \ClickHouseDB\Quote\FormatLine::TSV($row) . "\n", FILE_APPEND);
132 132
 }
133 133
 //
134 134
 echo "FILE:\n\n";
135
-echo file_get_contents($fileName)."\n\n----\n";
135
+echo file_get_contents($fileName) . "\n\n----\n";
136 136
 
137 137
 //
138 138
 $db->insertBatchTSVFiles('testTABWrite', [$fileName], [
@@ -144,9 +144,9 @@  discard block
 block discarded – undo
144 144
     'arrs',
145 145
 ]);
146 146
 
147
-$st=$db->select('SELECT * FROM testTABWrite');
147
+$st = $db->select('SELECT * FROM testTABWrite');
148 148
 print_r($st->rows());
149
-$st=$db->select('SELECT round(sum(flos),5),sum(ints) FROM testTABWrite');
149
+$st = $db->select('SELECT round(sum(flos),5),sum(ints) FROM testTABWrite');
150 150
 print_r($st->rows());
151 151
 
152 152
 //
153 153
\ No newline at end of file
Please login to merge, or discard this patch.
example/lib_example.php 1 patch
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -1,8 +1,8 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 date_default_timezone_set('Europe/Moscow');
4
-error_reporting( E_ALL );
5
-ini_set('display_errors',1);
4
+error_reporting(E_ALL);
5
+ini_set('display_errors', 1);
6 6
 
7 7
 /**
8 8
  * @param $file_name
@@ -53,38 +53,38 @@  discard block
 block discarded – undo
53 53
 
54 54
 class memoryUsage
55 55
 {
56
-    private static $last=[];
56
+    private static $last = [];
57 57
     /**
58 58
      * @return array
59 59
      */
60 60
     public static function memoryGetUsage()
61 61
     {
62
-        return ['mem'=>memory_get_usage(),'peak'=>memory_get_peak_usage()];
62
+        return ['mem'=>memory_get_usage(), 'peak'=>memory_get_peak_usage()];
63 63
 
64 64
     }
65 65
 
66 66
     public static function showPeak()
67 67
     {
68
-        echo "Peak        : \t".chr(27) ."[32m".humanFileSize(memory_get_peak_usage())."\033[0m "."\n";
68
+        echo "Peak        : \t" . chr(27) . "[32m" . humanFileSize(memory_get_peak_usage()) . "\033[0m " . "\n";
69 69
     }
70
-    public static function show($msg='')
70
+    public static function show($msg = '')
71 71
     {
72
-        $pre=false;
72
+        $pre = false;
73 73
         if (self::$last)
74 74
         {
75
-            $pre=self::$last;
75
+            $pre = self::$last;
76 76
         }
77
-        self::$last=self::memoryGetUsage();
78
-        $data=self::$last;
79
-        $txt=humanFileSize($data['mem']);
77
+        self::$last = self::memoryGetUsage();
78
+        $data = self::$last;
79
+        $txt = humanFileSize($data['mem']);
80 80
 
81 81
         if ($pre)
82 82
         {
83
-            $mem=$data['mem']-$pre['mem'];
84
-            $mem=($mem<0?'-':'+').humanFileSize(abs($mem));
85
-            $txt.= "\t\t\t Delta : ".$mem;
83
+            $mem = $data['mem'] - $pre['mem'];
84
+            $mem = ($mem < 0 ? '-' : '+') . humanFileSize(abs($mem));
85
+            $txt .= "\t\t\t Delta : " . $mem;
86 86
         }
87
-        echo "MemoryUsage : \t".chr(27) ."[33m".$txt."\033[0m ".($msg?' <<< '.$msg:'')."\n";
87
+        echo "MemoryUsage : \t" . chr(27) . "[33m" . $txt . "\033[0m " . ($msg ? ' <<< ' . $msg : '') . "\n";
88 88
     }
89 89
 }
90 90
 
@@ -180,7 +180,7 @@  discard block
 block discarded – undo
180 180
  * @param int $size
181 181
  * @return bool
182 182
  */
183
-function makeSomeDataFileBig($file_name, $size = 10,$shift=0)
183
+function makeSomeDataFileBig($file_name, $size = 10, $shift = 0)
184 184
 {
185 185
     if (is_file($file_name)) {
186 186
         echo "Exist file  [$file_name]: ± rows... size = " . humanFileSize(filesize($file_name)) . " \n";
@@ -201,7 +201,7 @@  discard block
 block discarded – undo
201 201
                 for ($hours = 0; $hours < 24; $hours++) {
202 202
                     $z++;
203 203
 
204
-                    $dt = strtotime('-' . ($dates+$shift) . ' day');
204
+                    $dt = strtotime('-' . ($dates + $shift) . ' day');
205 205
                     $dt = strtotime('-' . $hours . ' hour', $dt);
206 206
 
207 207
                     $j = [];
Please login to merge, or discard this patch.
example/exam14_Statistics_in_JSON.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -24,9 +24,9 @@
 block discarded – undo
24 24
 
25 25
 
26 26
 
27
-echo 'elapsed   :'.$result->statistics('elapsed')."\n";
28
-echo 'rows_read :'.$result->statistics('rows_read')."\n";
29
-echo 'bytes_read:'.$result->statistics('bytes_read')."\n";
27
+echo 'elapsed   :' . $result->statistics('elapsed') . "\n";
28
+echo 'rows_read :' . $result->statistics('rows_read') . "\n";
29
+echo 'bytes_read:' . $result->statistics('bytes_read') . "\n";
30 30
 
31 31
 //
32 32
 $result = $db->select("SELECT 12 as ping");
Please login to merge, or discard this patch.