File tree Expand file tree Collapse file tree 5 files changed +21
-5
lines changed
Expand file tree Collapse file tree 5 files changed +21
-5
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,10 @@ PHP ClickHouse wrapper - Changelog
55======================
66
77
8+ ### 2022-04-20 [ Release 1.4.4]
9+ * Fix ping() for windows users
10+ * ping(true) throw TransportException if can`t connect/ping
11+
812### 2022-04-20 [ Release 1.4.3]
913* Fix: prevent enable_http_compression parameter from being overridden #164
1014* For correct work with utf-8 . I am working on server with PHP 5.6.40 Update CurlerRequest.php #158
Original file line number Diff line number Diff line change @@ -37,9 +37,11 @@ composer require smi2/phpclickhouse
3737
3838In php
3939``` php
40+
4041// vendor autoload
4142$db = new ClickHouseDB\Client(['config_array']);
42- $db->ping();
43+
44+ if (!$db->ping()) echo 'Error connect';
4345```
4446
4547Last stable version for
@@ -64,7 +66,7 @@ $db->database('default');
6466$db->setTimeout(1.5); // 1500 ms
6567$db->setTimeout(10); // 10 seconds
6668$db->setConnectTimeOut(5); // 5 seconds
67-
69+ $db->ping(true); // if can`t connect throw exception
6870```
6971
7072Show tables:
Original file line number Diff line number Diff line change 55namespace ClickHouseDB ;
66
77use ClickHouseDB \Exception \QueryException ;
8+ use ClickHouseDB \Exception \TransportException ;
89use ClickHouseDB \Query \Degeneration ;
910use ClickHouseDB \Query \Degeneration \Bindings ;
1011use ClickHouseDB \Query \Degeneration \Conditions ;
@@ -735,11 +736,15 @@ public function tableSize(string $tableName)
735736 /**
736737 * Ping server
737738 *
739+ * @param bool $throwException
738740 * @return bool
741+ * @throws TransportException
739742 */
740- public function ping ()
743+ public function ping (bool $ throwException = false ): bool
741744 {
742- return $ this ->transport ()->ping ();
745+ $ result =$ this ->transport ()->ping ();
746+ if ($ throwException && !$ result ) throw new TransportException ('Can`t ping server ' );
747+ return $ result ;
743748 }
744749
745750 /**
Original file line number Diff line number Diff line change @@ -575,7 +575,7 @@ public function ping(): bool
575575 $ request ->url ($ this ->getUri ())->verbose (false )->GET ()->connectTimeOut ($ this ->getConnectTimeOut ());
576576 $ this ->_curler ->execOne ($ request );
577577
578- return $ request ->response ()->body () === 'Ok. ' . PHP_EOL ;
578+ return trim ( $ request ->response ()->body ()) === 'Ok. ' ;
579579 }
580580
581581 /**
Original file line number Diff line number Diff line change 55use ClickHouseDB \Client ;
66use ClickHouseDB \Exception \DatabaseException ;
77use ClickHouseDB \Exception \QueryException ;
8+ use ClickHouseDB \Exception \TransportException ;
89use ClickHouseDB \Query \WhereInFile ;
910use ClickHouseDB \Query \WriteToFile ;
1011use ClickHouseDB \Quote \FormatLine ;
@@ -803,6 +804,10 @@ public function testExceptionConnects()
803804
804805 $ db = new Client ($ config );
805806 $ this ->assertFalse ($ db ->ping ());
807+
808+ $ this ->expectException (TransportException::class);
809+ $ db ->ping (true );
810+
806811 }
807812
808813 public function testSettings ()
You can’t perform that action at this time.
0 commit comments