Skip to content

Commit a66c926

Browse files
committed
Merge branch 'PHP-8.3'
2 parents afffcae + e434385 commit a66c926

File tree

5 files changed

+170
-8
lines changed

5 files changed

+170
-8
lines changed

main/fastcgi.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1202,7 +1202,7 @@ static int fcgi_read_request(fcgi_request *req)
12021202
req->keep = 0;
12031203
return 0;
12041204
}
1205-
return 0;
1205+
return 2;
12061206
} else {
12071207
return 0;
12081208
}
@@ -1480,7 +1480,8 @@ int fcgi_accept_request(fcgi_request *req)
14801480
return -1;
14811481
}
14821482
req->hook.on_read();
1483-
if (fcgi_read_request(req)) {
1483+
int read_result = fcgi_read_request(req);
1484+
if (read_result == 1) {
14841485
#ifdef _WIN32
14851486
if (is_impersonate && !req->tcp) {
14861487
pipe = (HANDLE)_get_osfhandle(req->fd);
@@ -1491,7 +1492,7 @@ int fcgi_accept_request(fcgi_request *req)
14911492
}
14921493
#endif
14931494
return req->fd;
1494-
} else {
1495+
} else if (read_result == 0) {
14951496
fcgi_close(req, 1, 1);
14961497
}
14971498
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
--TEST--
2+
FPM: bug76922 - FCGI conn termination after FCGI_GET_VALUES
3+
--SKIPIF--
4+
<?php include "skipif.inc"; ?>
5+
--FILE--
6+
<?php
7+
8+
require_once "tester.inc";
9+
10+
$cfg = <<<EOT
11+
[global]
12+
error_log = {{FILE:LOG}}
13+
[unconfined]
14+
listen = {{ADDR}}
15+
pm = static
16+
pm.max_children = 1
17+
catch_workers_output = yes
18+
EOT;
19+
20+
$code = <<<EOT
21+
<?php
22+
echo 1;
23+
EOT;
24+
25+
$tester = new FPM\Tester($cfg, $code);
26+
$tester->start();
27+
$tester->expectLogStartNotices();
28+
$tester->requestValues(connKeepAlive: true)->expectValue('FCGI_MPXS_CONNS', '0');
29+
$tester->request(connKeepAlive: true)->expectBody('1');
30+
$tester->requestValues(connKeepAlive: true)->expectValue('FCGI_MPXS_CONNS', '0');
31+
$tester->terminate();
32+
$tester->close();
33+
34+
?>
35+
Done
36+
--EXPECT--
37+
Done
38+
--CLEAN--
39+
<?php
40+
require_once "tester.inc";
41+
FPM\Tester::clean();
42+
?>
43+
<?php

sapi/fpm/tests/fcgi.inc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -389,9 +389,9 @@ class Client
389389
const OVERLOADED = 2;
390390
const UNKNOWN_ROLE = 3;
391391

392-
const MAX_CONNS = 'MAX_CONNS';
393-
const MAX_REQS = 'MAX_REQS';
394-
const MPXS_CONNS = 'MPXS_CONNS';
392+
const MAX_CONNS = 'FCGI_MAX_CONNS';
393+
const MAX_REQS = 'FCGI_MAX_REQS';
394+
const MPXS_CONNS = 'FCGI_MPXS_CONNS';
395395

396396
const HEADER_LEN = 8;
397397

@@ -710,8 +710,8 @@ class Client
710710
$this->transport->write($this->buildPacket(self::GET_VALUES, $request, 0));
711711

712712
$resp = $this->readPacket();
713-
if ($resp['type'] == self::GET_VALUES_RESULT) {
714-
return $this->readNvpair($resp['content'], $resp['length']);
713+
if (isset($resp['type']) && $resp['type'] == self::GET_VALUES_RESULT) {
714+
return $this->readNvpair($resp['content'], $resp['contentLength']);
715715
} else {
716716
throw new \Exception('Unexpected response type, expecting GET_VALUES_RESULT');
717717
}

sapi/fpm/tests/response.inc

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,3 +460,89 @@ class Response
460460
return false;
461461
}
462462
}
463+
464+
class ValuesResponse
465+
{
466+
/**
467+
* @var array
468+
*/
469+
private array $values;
470+
471+
/**
472+
* @param string|array|null $values
473+
*/
474+
public function __construct($values = null)
475+
{
476+
if ( ! is_array($values)) {
477+
if ( ! is_null($values) ) {
478+
$this->error('Invalid values supplied', true);
479+
}
480+
$this->values = [];
481+
} else {
482+
$this->values = $values;
483+
}
484+
}
485+
486+
/**
487+
* Expect value.
488+
*
489+
* @param string $name
490+
* @param mixed $value
491+
* @return ValuesResponse
492+
*/
493+
public function expectValue(string $name, $value = null)
494+
{
495+
if ( ! isset($this->values[$name])) {
496+
return $this->error("Value $name not found in values");
497+
}
498+
if ( ! is_null($value) && $value !== $this->values[$name]) {
499+
return $this->error("Value $name is {$this->values[$name]} but expected $value");
500+
}
501+
return $this;
502+
}
503+
504+
/**
505+
* Get values.
506+
*
507+
* @return array
508+
*/
509+
public function getValues()
510+
{
511+
return $this->values;
512+
}
513+
514+
/**
515+
* Debug output data.
516+
*
517+
* @return ValuesResponse
518+
*/
519+
public function debugOutput()
520+
{
521+
echo ">>> ValuesResponse\n";
522+
echo "----------------- Values -----------------\n";
523+
var_dump($this->values);
524+
echo "---------------------------------------\n\n";
525+
526+
return $this;
527+
}
528+
529+
/**
530+
* Emit error message
531+
*
532+
* @param string $message
533+
* @param bool $throw
534+
*
535+
* @return ValuesResponse
536+
*/
537+
private function error(string $message, $throw = false): bool
538+
{
539+
$errorMessage = "ERROR: $message\n";
540+
if ($throw) {
541+
throw new \Exception($errorMessage);
542+
}
543+
$this->debugOutput();
544+
echo $errorMessage;
545+
546+
return $this;
547+
}
548+
}

sapi/fpm/tests/tester.inc

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -944,6 +944,38 @@ class Tester
944944
}
945945
}
946946

947+
/**
948+
* Execute request for getting FastCGI values.
949+
*
950+
* @param string|null $address
951+
* @param bool $connKeepAlive
952+
*
953+
* @return ValuesResponse
954+
* @throws \Exception
955+
*/
956+
public function requestValues(
957+
string $address = null,
958+
bool $connKeepAlive = false
959+
): ValuesResponse {
960+
if ($this->hasError()) {
961+
return new Response(null, true);
962+
}
963+
964+
try {
965+
$valueResponse = new ValuesResponse(
966+
$this->getClient($address, $connKeepAlive)->getValues(['FCGI_MPXS_CONNS'])
967+
);
968+
if ($this->debug) {
969+
$this->response->debugOutput();
970+
}
971+
} catch (\Exception $exception) {
972+
$this->error("Request for getting values failed", $exception);
973+
$valueResponse = new ValuesResponse();
974+
}
975+
976+
return $valueResponse;
977+
}
978+
947979
/**
948980
* Get client.
949981
*

0 commit comments

Comments
 (0)