1--TEST--
2FPM: Test excluding URIs from access log
3--SKIPIF--
4<?php include "skipif.inc"; ?>
5--FILE--
6<?php
7
8require_once "tester.inc";
9
10function doTestCalls(FPM\Tester &$tester, bool $expectSuppressableEntries)
11{
12    $tester->expectSuppressableAccessLogEntries($expectSuppressableEntries);
13
14    $tester->ping();
15    $tester->expectAccessLog("'GET /ping' 200", suppressable: true);
16
17    $tester->request()->expectBody('OK');
18    $tester->expectAccessLog("'GET /log-suppress-output.src.php' 200", suppressable: true);
19
20    $tester->ping();
21    $tester->expectAccessLog("'GET /ping' 200", suppressable: true);
22
23    $tester->request()->expectBody('OK');
24    $tester->expectAccessLog("'GET /log-suppress-output.src.php' 200", suppressable: true);
25
26    $tester->ping();
27    $tester->expectAccessLog("'GET /ping' 200", suppressable: true);
28
29    $tester->request(query: 'test=output')->expectBody('output');
30    $tester->expectAccessLog("'GET /log-suppress-output.src.php?test=output' 200", suppressable: false);
31
32    $tester->ping();
33    $tester->expectAccessLog("'GET /ping' 200", suppressable: true);
34
35    $tester->request()->expectBody('OK');
36    $tester->expectAccessLog("'GET /log-suppress-output.src.php' 200", suppressable: true);
37
38    $tester->request(query: 'test=output', uri: '/ping')->expectBody('pong', 'text/plain');
39    $tester->expectAccessLog("'GET /ping?test=output' 200", suppressable: false);
40
41    $tester->request(headers: ['X_ERROR' => 1])->expectBody('Not OK');
42    $tester->expectAccessLog("'GET /log-suppress-output.src.php' 500", suppressable: false);
43
44    $tester->request()->expectBody('OK');
45    $tester->expectAccessLog("'GET /log-suppress-output.src.php' 200", suppressable: true);
46
47    $tester->request(query: 'test=output', uri: '/ping')->expectBody('pong', 'text/plain');
48    $tester->expectAccessLog("'GET /ping?test=output' 200", suppressable: false);
49
50    $tester->ping();
51    $tester->expectAccessLog("'GET /ping' 200", suppressable: true);
52}
53
54$src = <<<EOT
55<?php
56if (isset(\$_SERVER['X_ERROR'])) {
57    echo "Not OK";
58    http_response_code(500);
59    exit;
60}
61echo \$_REQUEST['test'] ?? "OK";
62EOT;
63
64$cfg = <<<EOT
65[global]
66error_log = {{RFILE:LOG:ERR}}
67pid = {{RFILE:PID}}
68[unconfined]
69listen = {{ADDR}}
70access.log = {{RFILE:LOG:ACC}}
71access.format = "'%m %r%Q%q' %s"
72slowlog = {{RFILE:LOG:SLOW}}
73request_slowlog_timeout = 1
74ping.path = /ping
75ping.response = pong
76pm = dynamic
77pm.max_children = 5
78pm.start_servers = 2
79pm.min_spare_servers = 1
80pm.max_spare_servers = 3
81EOT;
82
83$prefix = __DIR__;
84$tester = new FPM\Tester($cfg, $src);
85$tester->start(['--prefix', $prefix]);
86$tester->expectLogStartNotices();
87doTestCalls($tester, expectSuppressableEntries: true);
88// Add source file and ping to ignore list
89$cfg = <<<EOT
90[global]
91error_log = {{RFILE:LOG:ERR}}
92pid = {{RFILE:PID}}
93[unconfined]
94listen = {{ADDR}}
95access.log = {{RFILE:LOG:ACC}}
96access.format = "'%m %r%Q%q' %s"
97access.suppress_path[] = /ping
98access.suppress_path[] = /log-suppress-output.src.php
99slowlog = {{RFILE:LOG:SLOW}}
100request_slowlog_timeout = 1
101ping.path = /ping
102ping.response = pong
103pm = dynamic
104pm.max_children = 5
105pm.start_servers = 2
106pm.min_spare_servers = 1
107pm.max_spare_servers = 3
108EOT;
109$tester->reload($cfg);
110$tester->expectLogReloadingNotices();
111doTestCalls($tester, expectSuppressableEntries: false);
112$tester->terminate();
113$tester->expectLogTerminatingNotices();
114$tester->close();
115$tester->expectNoFile(FPM\Tester::FILE_EXT_PID, $prefix);
116$tester->checkAccessLog();
117
118?>
119Done
120--EXPECT--
121Done
122--CLEAN--
123<?php
124require_once "tester.inc";
125FPM\Tester::clean();
126?>
127