Good Day! Im totally a newbie in PHP. Last time I posted a thread on how to create a script that measures the response times of retrieved records in a database. Or should I say how long the query took. Bpat1434 was kind enough to gave me a PHP code:
$query = "SELECT * FROM table ORDER BY id DESC";
$start = microtime(true); // get time of start
/**
Do your mySQL query in this area
/
$result = mysql_query($query);
$end = microtime(true); // Get ending time
$total = $end-$start;
echo 'Query took '.$total.' seconds to execute';
I built a client that will do a parallel searching for 3 open source library management systems. I inserted the PHP codes in the client. The codes goes like this:
<?php
// Adapted from http://www.php.net/manual/en/ref.yaz.php
$host=$REQUEST[host];
$query=$REQUEST[query];
$num_hosts = count($host);
if (empty($query) || count($host) == 0)
{
print "<html>
<head><style>
<!--
a:active { color:#0000FF; text-decoration; }
a:hover { color:#FF0000; text-decoration: none; }
a {text-decoration:none}
//-->
</style>
<title>
Z39.50 Origin
</title>
</head>
<body>
<br>
<br>
<br>
<table width=\"100%\" align=\"center\" border=\"1\">
<tr>
<td align=\"center\">
Parallel Searching
</td>
</tr>
<tr>
<td align=\"center\">
<form method=\"get\">
<input type=\"checkbox\" checked=\"checked\" name=\"host[]\" value=\"">PhpMyLibrary
<input type=\"checkbox\" checked=\"checked\" name=\"host[]\" value=\"">OpenBiblio
<input type=\"checkbox\" checked=\"checked\" name=\"host[]\" value=\"">Koha
<br>
<input name=\"query\" type=\"text\">
<input name=\"search\" type=\"submit\" value=\"Parallel Search\">
</form>
</td>
</tr>
</table>
<br>
<br>
<br>
<table width=\"100%\" align=\"center\" border=\"1\">
<tr>
<td align=\"center\">
Library Management Systems
</td>
</tr>
<tr>
<td align=\"center\">
<a href=\"">PhpMyLibrary</a> <i>
</td>
</tr>
<tr>
<td align=\"center\">
<a href=\"">OpenBiblio</a> <i>
<br>
<a href=\"">OpenBiblio Home</a> <i>
</td>
</tr>
<tr>
<td align=\"center\">
<a href=\"">Koha OPAC</a>
<br>
<a href=\"">Koha Intranet</a>
</td>
</tr>
</table>
</body>
</html>";
}
else
{
print "<html>
<head>
<title>
Z-Ker
</title>
</head>
<body>
<br>
<br>
<br>
<table width=\"100%\" align=\"center\" border=\"1\">
<tr>
<td align=\"center\">
Search Results for ".htmlspecialchars($query)."
</td>
</tr>
<tr>
<td>";
$start = "";
for ($i = 0; $i < $num_hosts; $i++)
{
$start = microtime(true); // get time of start
$id[] = yaz_connect($host[$i]);
#yaz_syntax($id[$i], "usmarc");
yaz_syntax($id[$i], "sutrs");
yaz_range($id[$i], 1, 10);
yaz_search($id[$i], "rpn", "@attr 1=1016 %".$query."%");
}
yaz_wait();
for ($i = 0; $i < $num_hosts; $i++)
{
echo '<hr />' . $host[$i] . ':<br>';
$error = yaz_error($id[$i]);
if (!empty($error))
{
echo "Error: $error";
}
else
{
$hits = yaz_hits($id[$i]);
echo "Number of Hits : $hits";
$end = microtime(true); // Get ending time
$total = $end-$start;
echo '<br>Start Time : '.$start;
echo '<br>End Time : '.$end;
echo '<br>Response Time : '.$total;
}
echo '<dl>';
for ($p = 1; $p <= 10; $p++)
{
$rec = yaz_record($id[$i], $p, "string");
if (empty($rec))
continue;
echo "<dt><b>$p</b></dt><dd>";
echo nl2br($rec);
echo "</dd>";
}
echo '</dl>';
}
print "</td>
</tr>
</table>
</body>
</html>";
}
?>
Unfortunately, I wasn't able to get reliable response times. Using the same keyword in searching, I got different response times on the same library management system.
Hope you guys can help me. Thanks!