Fast and Rich Apps |
|
2024-12-29 |
|
|
24 |
|
|
We'll benchmark a representative request to get an initial idea.
index.php
<?php
require_once "config.inc";
require_once "model.inc";
require_once "utils.inc";
require_once "head.inc";
head();
foreach(articles() as $row) {
$name = upper($row['name']);
echo <<<EOB
<tr>
<th>$name</th><td>{$row['age']}</td><td>{$row['entry']}</td>
</tr>
EOB;
}
boo();
foot();
?>
config.inc
<?php
$config = array(
'db' => 'pgsql',
'db_user' => 'nobody',
'db_pwd' => 'foobar',
'db_host' => 'localhost',
'db_db' => 'users',
'db_opts' => array(PDO::ERRMODE_EXCEPTION => true)
);
?>
model.inc
<?php
function articles() {
global $config;
try {
$dbh = new PDO($config['db'].':host='.$config['db_host'].';dbname='.$config['db_db'],
$config['db_user'],$config['db_pwd'], $config['db_opts']);
$q = "select users.name, users.age, data.entry
from users,data where data.name = users.name";
$result = $dbh->query($q,PDO::FETCH_ASSOC);
} catch (PDOException $e) {
echo "Error!: " . $e->getMessage();
die();
}
return $result;
}
?>
head.inc
<?php
function head() {
?>
<html><head><title>Index</title></head>
<body>
<table>
<?php
}
function foot() {
?>
</table></body></html>
<?php
}
?>
utils.inc
<?php
function upper($arg) {
return strtoupper($arg);
}
function boo() {
echo "boo";
}
?>