@@ -810,6 +810,7 @@ class Tester
810810 * @param string|null $successMessage
811811 * @param string|null $errorMessage
812812 * @param bool $connKeepAlive
813+ * @param bool $socketKeepAlive
813814 * @param string|null $scriptFilename = null
814815 * @param string|null $scriptName = null
815816 * @param string|array|null $stdin = null
@@ -828,6 +829,7 @@ class Tester
828829 string $ successMessage = null ,
829830 string $ errorMessage = null ,
830831 bool $ connKeepAlive = false ,
832+ bool $ socketKeepAlive = false ,
831833 string $ scriptFilename = null ,
832834 string $ scriptName = null ,
833835 string |array $ stdin = null ,
@@ -848,7 +850,8 @@ class Tester
848850
849851 try {
850852 $ 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 )
852855 );
853856 if ($ expectError ) {
854857 $ this ->error ('Expected request error but the request was successful ' );
@@ -879,6 +882,7 @@ class Tester
879882 * @param string|null $address
880883 * @param string|null $successMessage
881884 * @param string|null $errorMessage
885+ * @param bool $socketKeepAlive
882886 * @param bool $connKeepAlive
883887 * @param int $readTimeout
884888 * @param int $writeDelay
@@ -892,6 +896,7 @@ class Tester
892896 string $ successMessage = null ,
893897 string $ errorMessage = null ,
894898 bool $ connKeepAlive = false ,
899+ bool $ socketKeepAlive = false ,
895900 int $ readTimeout = 0 ,
896901 int $ writeDelay = 0 ,
897902 ) {
@@ -904,23 +909,26 @@ class Tester
904909 }
905910
906911 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+ }
918924
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+ );
924932
925933 $ responses = array_map (function ($ conn ) use ($ readTimeout ) {
926934 $ response = new Response ($ conn ['client ' ]->wait_for_response_data ($ conn ['requestId ' ], $ readTimeout ));
@@ -949,13 +957,15 @@ class Tester
949957 *
950958 * @param string|null $address
951959 * @param bool $connKeepAlive
960+ * @param bool $socketKeepAlive
952961 *
953962 * @return ValuesResponse
954963 * @throws \Exception
955964 */
956965 public function requestValues (
957966 string $ address = null ,
958- bool $ connKeepAlive = false
967+ bool $ connKeepAlive = false ,
968+ bool $ socketKeepAlive = false
959969 ): ValuesResponse {
960970 if ($ this ->hasError ()) {
961971 return new Response (null , true );
@@ -979,13 +989,17 @@ class Tester
979989 /**
980990 * Get client.
981991 *
982- * @param string $address
983- * @param bool $keepAlive
992+ * @param string|null $address
993+ * @param bool $connKeepAlive
994+ * @param bool $socketKeepAlive
984995 *
985996 * @return Client
986997 */
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 {
9891003 $ address = $ address ? $ this ->processTemplate ($ address ) : $ this ->getAddr ();
9901004 if ($ address [0 ] === '/ ' ) { // uds
9911005 $ host = 'unix:// ' . $ address ;
@@ -1005,13 +1019,16 @@ class Tester
10051019 $ port = $ addressParts [1 ] ?? $ this ->getPort ();
10061020 }
10071021
1008- if ( ! $ keepAlive ) {
1022+ if ($ socketKeepAlive ) {
1023+ $ connKeepAlive = true ;
1024+ }
1025+ if ( ! $ connKeepAlive ) {
10091026 return new Client ($ host , $ port , $ this ->createTransport ());
10101027 }
10111028
10121029 if ( ! isset ($ this ->clients [$ host ][$ port ])) {
10131030 $ client = new Client ($ host , $ port , $ this ->createTransport ());
1014- $ client ->setKeepAlive (true );
1031+ $ client ->setKeepAlive ($ connKeepAlive , $ socketKeepAlive );
10151032 $ this ->clients [$ host ][$ port ] = $ client ;
10161033 }
10171034
0 commit comments