@@ -8,11 +8,11 @@ discard block |
||
| 8 | 8 | |
| 9 | 9 | |
| 10 | 10 | $db = new ClickHouseDB\Client($config); |
| 11 | -$db->settings()->set('replication_alter_partitions_sync',2); |
|
| 12 | -$db->settings()->set('experimental_allow_extended_storage_definition_syntax',1); |
|
| 11 | +$db->settings()->set('replication_alter_partitions_sync', 2); |
|
| 12 | +$db->settings()->set('experimental_allow_extended_storage_definition_syntax', 1); |
|
| 13 | 13 | |
| 14 | 14 | |
| 15 | -for ( $looop=1;$looop<100;$looop++) |
|
| 15 | +for ($looop = 1; $looop < 100; $looop++) |
|
| 16 | 16 | { |
| 17 | 17 | |
| 18 | 18 | $db->write("DROP TABLE IF EXISTS testoperation_log"); |
@@ -26,29 +26,29 @@ discard block |
||
| 26 | 26 | "); |
| 27 | 27 | |
| 28 | 28 | echo "INSERT DATA....\n"; |
| 29 | - for ($z=0;$z<1000;$z++) |
|
| 29 | + for ($z = 0; $z < 1000; $z++) |
|
| 30 | 30 | { |
| 31 | - $dataInsert=['time'=>strtotime('-'.mt_rand(0,4000).' day'),'event'=>strval($z)]; |
|
| 31 | + $dataInsert = ['time'=>strtotime('-' . mt_rand(0, 4000) . ' day'), 'event'=>strval($z)]; |
|
| 32 | 32 | try { |
| 33 | - $db->insertAssocBulk('testoperation_log',$dataInsert); |
|
| 33 | + $db->insertAssocBulk('testoperation_log', $dataInsert); |
|
| 34 | 34 | echo "$z\r"; |
| 35 | 35 | } |
| 36 | 36 | catch (Exception $exception) |
| 37 | 37 | { |
| 38 | - die("Error:".$exception->getMessage()); |
|
| 38 | + die("Error:" . $exception->getMessage()); |
|
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | } |
| 42 | 42 | echo "INSER OK\n DROP PARTITION...\n"; |
| 43 | 43 | |
| 44 | - $partitons=($db->partitions('testoperation_log')); |
|
| 44 | + $partitons = ($db->partitions('testoperation_log')); |
|
| 45 | 45 | foreach ($partitons as $part) |
| 46 | 46 | { |
| 47 | - echo "$looop\t\t".$part['partition']."\t".$part['name']."\t".$part['active']."\r"; |
|
| 47 | + echo "$looop\t\t" . $part['partition'] . "\t" . $part['name'] . "\t" . $part['active'] . "\r"; |
|
| 48 | 48 | |
| 49 | - $db->dropPartition('default.testoperation_log',$part['partition']); |
|
| 49 | + $db->dropPartition('default.testoperation_log', $part['partition']); |
|
| 50 | 50 | } |
| 51 | - echo "SELECT count() ...".str_repeat(" ",300)."\n"; |
|
| 51 | + echo "SELECT count() ..." . str_repeat(" ", 300) . "\n"; |
|
| 52 | 52 | print_r($db->select('SELECT count() FROM default.testoperation_log')->rows()); |
| 53 | 53 | } |
| 54 | 54 | |
@@ -32,8 +32,7 @@ |
||
| 32 | 32 | try { |
| 33 | 33 | $db->insertAssocBulk('testoperation_log',$dataInsert); |
| 34 | 34 | echo "$z\r"; |
| 35 | - } |
|
| 36 | - catch (Exception $exception) |
|
| 35 | + } catch (Exception $exception) |
|
| 37 | 36 | { |
| 38 | 37 | die("Error:".$exception->getMessage()); |
| 39 | 38 | } |
@@ -11,12 +11,12 @@ |
||
| 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 | |
@@ -10,15 +10,15 @@ |
||
| 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 | { |
@@ -12,27 +12,27 @@ |
||
| 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); |
@@ -7,13 +7,13 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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 | |
@@ -29,7 +29,7 @@ |
||
| 29 | 29 | { |
| 30 | 30 | try{ |
| 31 | 31 | $x=$cl->activeClient()->write("DROP TABLE IF EXISTS default.asdasdasd ON CLUSTER cluster2"); |
| 32 | - }catch (Exception $exception) |
|
| 32 | + } catch (Exception $exception) |
|
| 33 | 33 | { |
| 34 | 34 | |
| 35 | 35 | } |
@@ -12,16 +12,16 @@ |
||
| 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 | // ---------------------------------------------------------------------- |
@@ -10,7 +10,7 @@ discard block |
||
| 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 |
||
| 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"; |
@@ -51,7 +51,7 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
@@ -1,8 +1,8 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 = []; |
@@ -157,8 +157,10 @@ |
||
| 157 | 157 | |
| 158 | 158 | for ($day_ago = 0; $day_ago < 360; $day_ago++) { |
| 159 | 159 | $date = strtotime('-' . $day_ago . ' day'); |
| 160 | - for ($hash_id = 1; $hash_id < (1 + $size); $hash_id++) |
|
| 161 | - for ($site_id = 100; $site_id < 199; $site_id++) { |
|
| 160 | + for ($hash_id = 1; $hash_id < (1 + $size); $hash_id++) { |
|
| 161 | + for ($site_id = 100; |
|
| 162 | + } |
|
| 163 | + $site_id < 199; $site_id++) { |
|
| 162 | 164 | $j['event_time'] = date('Y-m-d H:00:00', $date); |
| 163 | 165 | $j['site_id'] = $site_id; |
| 164 | 166 | $j['hash_id'] = $hash_id; |