Skip to content

Commit 39799af

Browse files
committed
Improve keep alive handling and setting fcgi transport in FPM tester
1 parent 53e769c commit 39799af

File tree

2 files changed

+43
-13
lines changed

2 files changed

+43
-13
lines changed

sapi/fpm/tests/fcgi.inc

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,11 @@ class StreamTransport implements Transport
104104
*/
105105
private $stream = null;
106106

107+
/**
108+
* @var bool
109+
*/
110+
private bool $keepAlive = false;
111+
107112
/**
108113
* @inheritDoc
109114
*/
@@ -123,6 +128,10 @@ class StreamTransport implements Transport
123128
if (!$this->stream) {
124129
throw new TransportException('Unable to connect to FastCGI application: ' . $errstr);
125130
}
131+
132+
if ($this->keepAlive) {
133+
$this->setKeepAlive(true);
134+
}
126135
}
127136

128137
/**
@@ -145,6 +154,10 @@ class StreamTransport implements Transport
145154
*/
146155
public function setKeepAlive(bool $keepAlive): void
147156
{
157+
$this->keepAlive = $keepAlive;
158+
if (!$this->stream) {
159+
return;
160+
}
148161
if ($keepAlive) {
149162
$socket = socket_import_stream($this->stream);
150163
if ($socket) {
@@ -219,9 +232,14 @@ class SocketTransport implements Transport
219232
private ?\Socket $socket = null;
220233

221234
/**
222-
* @inheritDoc
235+
* @var int
236+
*/
237+
protected int $dataTimeoutMs = 5000;
238+
239+
/**
240+
* @var bool
223241
*/
224-
protected int $dataTimeoutMs;
242+
private bool $keepAlive = false;
225243

226244
/**
227245
* @inheritDoc
@@ -242,6 +260,10 @@ class SocketTransport implements Transport
242260
$error = socket_strerror(socket_last_error($this->socket));
243261
throw new TransportException('Unable to connect to FastCGI application: ' . $error);
244262
}
263+
264+
if ($this->keepAlive) {
265+
$this->setKeepAlive(true);
266+
}
245267
}
246268

247269
/**
@@ -258,6 +280,7 @@ class SocketTransport implements Transport
258280
*/
259281
public function setKeepAlive(bool $keepAlive): void
260282
{
283+
$this->keepAlive = $keepAlive;
261284
if (!$this->socket) {
262285
return;
263286
}

sapi/fpm/tests/tester.inc

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ class Tester
6565
*/
6666
private array $clients = [];
6767

68+
/**
69+
* @var string
70+
*/
71+
private string $clientTransport;
72+
6873
/**
6974
* @var LogReader
7075
*/
@@ -355,15 +360,17 @@ class Tester
355360
string $code = '',
356361
array $options = [],
357362
string $fileName = null,
358-
bool $debug = null
363+
bool $debug = null,
364+
string $clientTransport = 'stream'
359365
) {
360-
$this->configTemplate = $configTemplate;
361-
$this->code = $code;
362-
$this->options = $options;
363-
$this->fileName = $fileName ?: self::getCallerFileName();
364-
$this->debug = $debug !== null ? $debug : (bool)getenv('TEST_FPM_DEBUG');
365-
$this->logReader = new LogReader($this->debug);
366-
$this->logTool = new LogTool($this->logReader, $this->debug);
366+
$this->configTemplate = $configTemplate;
367+
$this->code = $code;
368+
$this->options = $options;
369+
$this->fileName = $fileName ?: self::getCallerFileName();
370+
$this->debug = $debug !== null ? $debug : (bool)getenv('TEST_FPM_DEBUG');
371+
$this->logReader = new LogReader($this->debug);
372+
$this->logTool = new LogTool($this->logReader, $this->debug);
373+
$this->clientTransport = $clientTransport;
367374
}
368375

369376
/**
@@ -894,7 +901,7 @@ class Tester
894901
*
895902
* @return Client
896903
*/
897-
private function getClient(string $address = null, $keepAlive = false): Client
904+
private function getClient(string $address = null, bool $keepAlive = false): Client
898905
{
899906
$address = $address ? $this->processTemplate($address) : $this->getAddr();
900907
if ($address[0] === '/') { // uds
@@ -916,11 +923,11 @@ class Tester
916923
}
917924

918925
if ( ! $keepAlive) {
919-
return new Client($host, $port);
926+
return new Client($host, $port, $this->clientTransport);
920927
}
921928

922929
if ( ! isset($this->clients[$host][$port])) {
923-
$client = new Client($host, $port);
930+
$client = new Client($host, $port, $this->clientTransport);
924931
$client->setKeepAlive(true);
925932
$this->clients[$host][$port] = $client;
926933
}

0 commit comments

Comments
 (0)