@@ -810,6 +810,7 @@ class Tester
810
810
* @param string|null $successMessage
811
811
* @param string|null $errorMessage
812
812
* @param bool $connKeepAlive
813
+ * @param bool $socketKeepAlive
813
814
* @param string|null $scriptFilename = null
814
815
* @param string|null $scriptName = null
815
816
* @param string|array|null $stdin = null
@@ -828,6 +829,7 @@ class Tester
828
829
string $ successMessage = null ,
829
830
string $ errorMessage = null ,
830
831
bool $ connKeepAlive = false ,
832
+ bool $ socketKeepAlive = false ,
831
833
string $ scriptFilename = null ,
832
834
string $ scriptName = null ,
833
835
string |array $ stdin = null ,
@@ -848,7 +850,8 @@ class Tester
848
850
849
851
try {
850
852
$ this ->response = new Response (
851
- $ this ->getClient ($ address , $ connKeepAlive )->request_data ($ params , $ stdin , $ readLimit , $ writeDelay )
853
+ $ this ->getClient ($ address , $ connKeepAlive , $ socketKeepAlive )
854
+ ->request_data ($ params , $ stdin , $ readLimit , $ writeDelay )
852
855
);
853
856
if ($ expectError ) {
854
857
$ this ->error ('Expected request error but the request was successful ' );
@@ -879,6 +882,7 @@ class Tester
879
882
* @param string|null $address
880
883
* @param string|null $successMessage
881
884
* @param string|null $errorMessage
885
+ * @param bool $socketKeepAlive
882
886
* @param bool $connKeepAlive
883
887
* @param int $readTimeout
884
888
* @param int $writeDelay
@@ -892,6 +896,7 @@ class Tester
892
896
string $ successMessage = null ,
893
897
string $ errorMessage = null ,
894
898
bool $ connKeepAlive = false ,
899
+ bool $ socketKeepAlive = false ,
895
900
int $ readTimeout = 0 ,
896
901
int $ writeDelay = 0 ,
897
902
) {
@@ -904,23 +909,26 @@ class Tester
904
909
}
905
910
906
911
try {
907
- $ connections = array_map (function ($ requestData ) use ($ address , $ connKeepAlive , $ writeDelay ) {
908
- $ client = $ this ->getClient ($ address , $ connKeepAlive );
909
- $ params = $ this ->getRequestParams (
910
- $ requestData ['query ' ] ?? '' ,
911
- $ requestData ['headers ' ] ?? [],
912
- $ requestData ['uri ' ] ?? null
913
- );
914
-
915
- if (isset ($ requestData ['delay ' ])) {
916
- usleep ($ requestData ['delay ' ]);
917
- }
912
+ $ connections = array_map (
913
+ function ($ requestData ) use ($ address , $ connKeepAlive , $ socketKeepAlive , $ writeDelay ) {
914
+ $ client = $ this ->getClient ($ address , $ connKeepAlive , $ socketKeepAlive );
915
+ $ params = $ this ->getRequestParams (
916
+ $ requestData ['query ' ] ?? '' ,
917
+ $ requestData ['headers ' ] ?? [],
918
+ $ requestData ['uri ' ] ?? null
919
+ );
920
+
921
+ if (isset ($ requestData ['delay ' ])) {
922
+ usleep ($ requestData ['delay ' ]);
923
+ }
918
924
919
- return [
920
- 'client ' => $ client ,
921
- 'requestId ' => $ client ->async_request ($ params , false , $ writeDelay ),
922
- ];
923
- }, $ requests );
925
+ return [
926
+ 'client ' => $ client ,
927
+ 'requestId ' => $ client ->async_request ($ params , false , $ writeDelay ),
928
+ ];
929
+ },
930
+ $ requests
931
+ );
924
932
925
933
$ responses = array_map (function ($ conn ) use ($ readTimeout ) {
926
934
$ response = new Response ($ conn ['client ' ]->wait_for_response_data ($ conn ['requestId ' ], $ readTimeout ));
@@ -949,13 +957,15 @@ class Tester
949
957
*
950
958
* @param string|null $address
951
959
* @param bool $connKeepAlive
960
+ * @param bool $socketKeepAlive
952
961
*
953
962
* @return ValuesResponse
954
963
* @throws \Exception
955
964
*/
956
965
public function requestValues (
957
966
string $ address = null ,
958
- bool $ connKeepAlive = false
967
+ bool $ connKeepAlive = false ,
968
+ bool $ socketKeepAlive = false
959
969
): ValuesResponse {
960
970
if ($ this ->hasError ()) {
961
971
return new Response (null , true );
@@ -979,13 +989,17 @@ class Tester
979
989
/**
980
990
* Get client.
981
991
*
982
- * @param string $address
983
- * @param bool $keepAlive
992
+ * @param string|null $address
993
+ * @param bool $connKeepAlive
994
+ * @param bool $socketKeepAlive
984
995
*
985
996
* @return Client
986
997
*/
987
- private function getClient (string $ address = null , bool $ keepAlive = false ): Client
988
- {
998
+ private function getClient (
999
+ string $ address = null ,
1000
+ bool $ connKeepAlive = false ,
1001
+ bool $ socketKeepAlive = false
1002
+ ): Client {
989
1003
$ address = $ address ? $ this ->processTemplate ($ address ) : $ this ->getAddr ();
990
1004
if ($ address [0 ] === '/ ' ) { // uds
991
1005
$ host = 'unix:// ' . $ address ;
@@ -1005,13 +1019,16 @@ class Tester
1005
1019
$ port = $ addressParts [1 ] ?? $ this ->getPort ();
1006
1020
}
1007
1021
1008
- if ( ! $ keepAlive ) {
1022
+ if ($ socketKeepAlive ) {
1023
+ $ connKeepAlive = true ;
1024
+ }
1025
+ if ( ! $ connKeepAlive ) {
1009
1026
return new Client ($ host , $ port , $ this ->createTransport ());
1010
1027
}
1011
1028
1012
1029
if ( ! isset ($ this ->clients [$ host ][$ port ])) {
1013
1030
$ client = new Client ($ host , $ port , $ this ->createTransport ());
1014
- $ client ->setKeepAlive (true );
1031
+ $ client ->setKeepAlive ($ connKeepAlive , $ socketKeepAlive );
1015
1032
$ this ->clients [$ host ][$ port ] = $ client ;
1016
1033
}
1017
1034
0 commit comments