-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathapp.php
More file actions
64 lines (54 loc) · 1.36 KB
/
app.php
File metadata and controls
64 lines (54 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
require 'Pgsql.php';
// Init
Pgsql::init();
define('JSON_DATA', json_decode(file_get_contents('/data/dataset.json'), true));
function baseline()
{
$sum = array_sum(ngx::query_args());
if(ngx_request_method() === 'POST') {
$sum += ngx_request_body();
}
ngx_header_set('Content-Type', 'text/plain');
echo $sum;
}
function json()
{
$count = explode('/', ngx_request_document_uri())[2];
$m = ngx_query_args()['m'] ?? 1;
$total = [];
$i = 0;
while ($i < $count) {
$item = JSON_DATA[$i++];
$item['total'] = $item['price'] * $item['quantity'] * $m;
$total[] = $item;
}
ngx_header_set('Content-Type', 'application/json');
echo json_encode(['items' => $total, 'count' => $count],
JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
}
function upload()
{
ngx_header_set('Content-Type', 'text/plain');
echo strlen(ngx_request_body());
}
function pipeline()
{
ngx_header_set('Content-Type', 'text/plain');
echo 'ok';
}
function asyncDb()
{
ngx_header_set('Content-Type', 'application/json');
echo Pgsql::query(
ngx::query_args()['min'] ?? 10,
ngx::query_args()['max'] ?? 50,
ngx::query_args()['limit'] ?? 50
);
}
function notFound()
{
ngx_header_set('Content-Type', 'text/plain');
echo 'Not Found';
ngx_status(404);
}