@@ -527,7 +527,10 @@ public function isSupported($fe_key = 'session_id', $re_check = false)
527
527
/**
528
528
* Return version of ClickHouse server by function SELECT version()
529
529
*
530
- * The response is cached
530
+ * Do SELECT version() + session_id to see if a session is supported or not
531
+ * if session_id not supported, request is send again, but without session_id.
532
+ * - Depending on result, the isSupported('session_id') is set true or false.
533
+ * - If server version response unrecognized, isSupported('query') set false.
531
534
*
532
535
* @param boolean $re_check Set true for re-send query to server
533
536
* @return string|boolean String version or false if error
@@ -536,32 +539,40 @@ public function getVersion($re_check = false)
536
539
{
537
540
if (\is_null ($ this ->server_version ) || $ re_check ) {
538
541
$ old_sess = $ this ->setSession (null , false );
539
- $ session_id = $ this ->getSession ();
540
542
$ query = 'SELECT version() ' ;
541
- $ user = $ this ->user ;
542
- $ password = $ this ->pass ;
543
- $ h_opt_arr = \compact ('query ' , 'user ' , 'password ' , 'session_id ' );
544
- $ ans = $ this ->doApiCall ($ this ->server_url , $ h_opt_arr );
545
- if ($ ans ['code ' ] == 200 ) {
546
- $ this ->support_fe ['session_id ' ] = true ;
547
- } else {
548
- $ this ->support_fe ['session_id ' ] = false ;
549
- $ this ->session_autocreate = false ;
550
- unset($ h_opt_arr ['session_id ' ]);
551
- // if session_id unsupported send request again
552
- if ($ ans ['code ' ] == 404 ) {
553
- $ ans = $ this ->doApiCall ($ this ->server_url , $ h_opt_arr );
554
- }
543
+ $ ans = $ this ->doGet ($ query , ['session_id ' => $ this ->getSession ()]);
544
+ if (!($ this ->support_fe ['session_id ' ] = $ ans ['code ' ] != 404 )) {
545
+ $ ans = $ this ->doGet ($ query );
555
546
}
556
547
$ ver = explode ("\n" , $ ans ['response ' ]);
557
548
$ ver = (count ($ ver ) == 2 && strlen ($ ver [0 ]) < 32 ) ? $ ver [0 ] : "Unknown " ;
558
549
$ this ->support_fe ['query ' ] = \is_string ($ ver ) && (\count (\explode (". " , $ ver )) > 2 );
559
550
if (!$ this ->support_fe ['query ' ]) {
560
551
$ this ->support_fe ['session_id ' ] = false ;
561
552
}
553
+ if (!$ this ->support_fe ['session_id ' ]) {
554
+ $ this ->session_autocreate = false ;
555
+ }
562
556
$ this ->server_version = $ ver ;
563
557
$ this ->setOption ('session_id ' , $ old_sess );
564
558
}
565
559
return $ this ->server_version ;
566
560
}
561
+
562
+ /**
563
+ * Do GET-request with base options (query, user, password) + specified options
564
+ *
565
+ * The result array is the same as for the function doApiCall
566
+ *
567
+ * @param string $query will be set as an option ?query=...
568
+ * @param array $h_opt Other in-url-options for make GET-request
569
+ * @return array
570
+ */
571
+ public function doGet ($ query , $ h_opt = [])
572
+ {
573
+ $ user = $ this ->user ;
574
+ $ password = $ this ->pass ;
575
+ $ h_opt_arr = \array_merge (\compact ('query ' , 'user ' , 'password ' ), $ h_opt );
576
+ return $ this ->doApiCall ($ this ->server_url , $ h_opt_arr );
577
+ }
567
578
}
0 commit comments