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
5
5
======================
6
6
7
7
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
+
8
12
### 2022-04-20 [ Release 1.4.3]
9
13
* Fix: prevent enable_http_compression parameter from being overridden #164
10
14
* 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
37
37
38
38
In php
39
39
``` php
40
+
40
41
// vendor autoload
41
42
$db = new ClickHouseDB\Client(['config_array']);
42
- $db->ping();
43
+
44
+ if (!$db->ping()) echo 'Error connect';
43
45
```
44
46
45
47
Last stable version for
@@ -64,7 +66,7 @@ $db->database('default');
64
66
$db->setTimeout(1.5); // 1500 ms
65
67
$db->setTimeout(10); // 10 seconds
66
68
$db->setConnectTimeOut(5); // 5 seconds
67
-
69
+ $db->ping(true); // if can`t connect throw exception
68
70
```
69
71
70
72
Show tables:
Original file line number Diff line number Diff line change 5
5
namespace ClickHouseDB ;
6
6
7
7
use ClickHouseDB \Exception \QueryException ;
8
+ use ClickHouseDB \Exception \TransportException ;
8
9
use ClickHouseDB \Query \Degeneration ;
9
10
use ClickHouseDB \Query \Degeneration \Bindings ;
10
11
use ClickHouseDB \Query \Degeneration \Conditions ;
@@ -735,11 +736,15 @@ public function tableSize(string $tableName)
735
736
/**
736
737
* Ping server
737
738
*
739
+ * @param bool $throwException
738
740
* @return bool
741
+ * @throws TransportException
739
742
*/
740
- public function ping ()
743
+ public function ping (bool $ throwException = false ): bool
741
744
{
742
- return $ this ->transport ()->ping ();
745
+ $ result =$ this ->transport ()->ping ();
746
+ if ($ throwException && !$ result ) throw new TransportException ('Can`t ping server ' );
747
+ return $ result ;
743
748
}
744
749
745
750
/**
Original file line number Diff line number Diff line change @@ -575,7 +575,7 @@ public function ping(): bool
575
575
$ request ->url ($ this ->getUri ())->verbose (false )->GET ()->connectTimeOut ($ this ->getConnectTimeOut ());
576
576
$ this ->_curler ->execOne ($ request );
577
577
578
- return $ request ->response ()->body () === 'Ok. ' . PHP_EOL ;
578
+ return trim ( $ request ->response ()->body ()) === 'Ok. ' ;
579
579
}
580
580
581
581
/**
Original file line number Diff line number Diff line change 5
5
use ClickHouseDB \Client ;
6
6
use ClickHouseDB \Exception \DatabaseException ;
7
7
use ClickHouseDB \Exception \QueryException ;
8
+ use ClickHouseDB \Exception \TransportException ;
8
9
use ClickHouseDB \Query \WhereInFile ;
9
10
use ClickHouseDB \Query \WriteToFile ;
10
11
use ClickHouseDB \Quote \FormatLine ;
@@ -803,6 +804,10 @@ public function testExceptionConnects()
803
804
804
805
$ db = new Client ($ config );
805
806
$ this ->assertFalse ($ db ->ping ());
807
+
808
+ $ this ->expectException (TransportException::class);
809
+ $ db ->ping (true );
810
+
806
811
}
807
812
808
813
public function testSettings ()
You can’t perform that action at this time.
0 commit comments