Skip to content

Commit

Permalink
Fix phpGH-16932: wrong FPM status output
Browse files Browse the repository at this point in the history
  • Loading branch information
bukka committed Nov 27, 2024
1 parent e47f181 commit b68ef83
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 2 deletions.
2 changes: 1 addition & 1 deletion sapi/fpm/fpm/fpm_request.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ void fpm_request_end(void)
fpm_scoreboard_proc_release(proc);

/* memory_peak */
fpm_scoreboard_update_commit(0, 0, 0, 0, 0, 0, 0, proc->memory, FPM_SCOREBOARD_ACTION_SET, NULL);
fpm_scoreboard_update_commit(-1, -1, -1, -1, -1, -1, -1, proc->memory, FPM_SCOREBOARD_ACTION_SET, NULL);
}

void fpm_request_finished(void)
Expand Down
56 changes: 56 additions & 0 deletions sapi/fpm/tests/gh16932-scoreboard-reset.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
--TEST--
FPM: GH-16932 - scoreboard fields are reset after the request
--EXTENSIONS--
pcntl
--SKIPIF--
<?php
include "skipif.inc";
?>
--FILE--
<?php

require_once "tester.inc";

$cfg = <<<EOT
[global]
error_log = {{FILE:LOG}}
pid = {{FILE:PID}}
[unconfined]
listen = {{ADDR}}
pm.status_path = /status
pm = dynamic
pm.max_children = 2
pm.start_servers = 1
pm.min_spare_servers = 1
pm.max_spare_servers = 1
EOT;

$code = <<<EOT
<?php
echo "hi!";
EOT;


$tester = new FPM\Tester($cfg, $code);
$tester->start(extensions: ['pcntl']);
$tester->expectLogStartNotices();
$tester->request();
$tester->request();
$tester->request();
$tester->request();
$tester
->request(uri: '/status', query: 'json')
->expectJsonBodyPatternForStatusField('accepted conn', '5');
$tester->terminate();
$tester->expectLogTerminatingNotices();
$tester->close();

?>
Done
--EXPECT--
Done
--CLEAN--
<?php
require_once "tester.inc";
FPM\Tester::clean();
?>
25 changes: 24 additions & 1 deletion sapi/fpm/tests/response.inc
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,29 @@ class Response extends BaseResponse
return $this;
}

/**
* Expect status field with value that matches the supplied pattern.
*
* @param string $fieldName
* @param string $pattern
*
* @return Response
*/
public function expectJsonBodyPatternForStatusField(string $fieldName, string $pattern): Response
{
$rawData = $this->getBody('application/json');
$data = json_decode($rawData, true);
if (preg_match('|' . $pattern . '|', $data[$fieldName]) > 0) {
return $this;
}

$this->error(
"Field $fieldName did not match pattern $pattern in status data '$rawData'"
);

return $this;
}

/**
* Expect that one of the processes in json status process list has a field with value that
* matches the supplied pattern.
Expand All @@ -167,7 +190,7 @@ class Response extends BaseResponse
);
}
foreach ($data['processes'] as $process) {
if (preg_match('|' . $pattern . '|', $process[$fieldName]) !== false) {
if (preg_match('|' . $pattern . '|', $process[$fieldName]) > 0) {
return $this;
}
}
Expand Down

0 comments on commit b68ef83

Please sign in to comment.