Skip to content

Commit

Permalink
Create Test TechEmpower#4 Fortunes.
Browse files Browse the repository at this point in the history
  • Loading branch information
herloct committed Oct 18, 2016
1 parent 5a7dd28 commit d2f9afc
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions frameworks/PHP/slim/benchmark_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"query_url": "/queries?queries=",
"plaintext_url": "/plaintext",
"update_url": "/updates?queries",
"fortune_url": "/fortunes",
"port": 8080,
"approach": "Realistic",
"classification": "Micro",
Expand Down
22 changes: 22 additions & 0 deletions frameworks/PHP/slim/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,28 @@
}
);

// Test 4: Fortunes
$app->get('/fortunes', function ($request, $response) {
$sth = $this->db->query('SELECT * FROM fortune');

$arr = $sth->fetch(PDO::FETCH_KEY_PAIR);
$arr[0] = 'Additional fortune added at request time.';
asort($arr);

ob_start();
include __DIR__.'/index.tpl.phtml';
$html = ob_get_contents();
ob_end_clean();

$body = $response->getBody();
$body->write($html);

return $response
->withBody($body)
->withHeader('Content-Type', 'text/html');
}
);

// Test 5: Database updates
$app->get('/updates', function ($request, $response) {
$sth = $this->db->prepare('SELECT * FROM world WHERE id = ?');
Expand Down
12 changes: 12 additions & 0 deletions frameworks/PHP/slim/index.tpl.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html>
<head><title>Fortunes</title></head>
<body>
<table>
<tr><th>id</th><th>message</th></tr>
<?php foreach ($arr as $id => $message): ?>
<tr><td><?=$id?></td><td><?=$message?></td></tr>
<?php endforeach; ?>
</table>
</body>
</html>

0 comments on commit d2f9afc

Please sign in to comment.