Skip navigation.
Home

Bad Architecture

Holy SQL Batman!

Bad Architecture

Thanks to Alex @ The Daily WTF for forwarding this to me. This little chunk of code comes from a home made discussion forum. Too bad I didn't get this before Halloween because it's high on the scary factor.

There's nothing like doing 35 string operations in a SQL query to make sure your database server isn't slacking off.

<?php
function Odcesti($slovo,$nazevsloupce)
{

$exp = explode(" ", strtolower($slovo));
$query = implode("%", $exp);

$query=StrTr($query,
"\xC1\xC8\xCF\xC9\xCC\xCD\xBC\xD2\xD3\xD4\xD8\x8A".
"\x8D\xDA\xD9\xDD\x8E\xE1\xE8\xEF\xE9\xEC\xED".
"\xBE\xF2\xF4\xF3\xF8\x9A\x9D\xFA\xF9\xFD\x9E",
"acdeeilnoorstuuyzacdeeilnoorstuuyz");

return
" LOWER(
REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE(
REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE(
REPLACE( REPLACE( REPLACE( REPLACE( REPLACE(
REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE(
REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE(
REPLACE( REPLACE( REPLACE( REPLACE( REPLACE($nazevsloupce,
'\xC1','a'),'\xC8','c'),'\xCF','d'),'\xC9','e'),'\xCC','e'),
'\xCD','i'),'\xBC','l'),'\xD2','n'),'\xD3','o'),'\xD4','o'),
'\xD8','r'),'\x8A','s'),'\x8D','t'),'\xDA','u'),'\xD9','u'),
'\xDD','y'),'\x8E','z'),'\xE1','a'),'\xE8','c'),'\xEF','d'),
'\xE9','e'),'\xEC','e'),'\xED','i'),'\xBE','l'),'\xF2','n'),
'\xF4','o'),'\xF3','o'),'\xF8','r'),'\x9A','s'),'\x9D','t'),
'\xFA','u'),'\xF9','u'),'\xFD','y'),'\x9E','z')) like '%$query%'"
;
}
?>

Why is my code so slow?

Hall of Fame | Bad Architecture

Don't you hate it when the Internet makes your PHP run slow? I do. Props to Andrew Lindeman for sending this snippet in. I trimmed it to reduce the boring.

This code checks the status of a bunch of Diablo II game servers and generates a pretty table that shows a server's status. Unfortunately the code runs really, really slow. Damn the Internet!

<style type="text/css">
<!--
...
-->
</style>
<p align="center" class="style1">Overall PKA Server Status</p>
<table width="100%" border="0" align="center" cellspacing="0">
 <tr bordercolor="#990000" bgcolor="#990000">
   <td><strong>Diablo II Realms </strong></td>
   <td bgcolor="#FF0000"><span class="style5">Status</span></td>
   <td bgcolor="#660000"><strong>Diablo II Game Servers 1 </strong></td>
   <td bgcolor="#660000"> </td>
   <td bgcolor="#660000"><span class="style6">Diablo II Game Servers 2 </span></td>
   <td bgcolor="#660000"> </td>
 </tr>
 <tr>
   <td width="172">Diablo II  Open Server is :</td>
   <td width="121"><?php
if ($fp = @fsockopen("bnet.pkaclan.com","6112")) { echo "<img src=images/open.gif>"; } else { echo "<img src=images/closed.gif>"; }
?></td>
...
 </tr>
 <tr>
   <td>PKA Realm is :</td>
   <td><?php
if ($fp = @fsockopen("bnet.pkaclan.com","6113")) { echo "<img src=images/open.gif>"; } else { echo "<img src=images/closed.gif>"; }
?></td>
   <td>D2GS PKA1.1(Soulzek):</td>
   <td><?php
if ($fp = @fsockopen("68.56.114.98","4000")) { echo "<img src=images/open.gif>"; } else { echo "<img src=images/closed.gif>"; }
?></td>
   <td> </td>
   <td> </td>
 </tr>
 <tr>
   <td>PvP Realm is :</td>
   <td><?php
if ($fp = @fsockopen("bnet.pkaclan.com","7113")) { echo "<img src=images/open.gif>"; } else { echo "<img src=images/closed.gif>"; }
?></td>
   <td>D2GS PvP1.09(<SPAN class=postbody>Shiznoo</SPAN>):</td>
   <td><?php
if ($fp = @fsockopen("141.158.150.28","4000")) { echo "<img src=images/open.gif>"; } else { echo "<img src=images/closed.gif>"; }
?></td>
   <td> </td>
   <td> </td>
 </tr>
 <tr>
   <td>Ancestrall Recall Realm is :</td>
   <td><?php
if ($fp = @fsockopen("bnet.pkaclan.com","8113")) { echo "<img src=images/open.gif>"; } else { echo "<img src=images/closed.gif>"; }
?></td>
   <td>D2GS AR1.10(Wallbot):</td>
   <td><?php
if ($fp = @fsockopen("wow.pkaclan.com","4000")) { echo "<img src=images/open.gif>"; } else { echo "<img src=images/closed.gif>"; }
?></td>
   <td> </td>
   <td> </td>
 </tr>
 <tr>
   <td>Hell Unleashed Realm is : </td>
   <td><?php
if ($fp = @fsockopen("bnet.pkaclan.com","9113")) { echo "<img src=images/open.gif>"; } else { echo "<img src=images/closed.gif>"; }
?></td>
   <td>D2GS HU1.10 (Gnecromancer): </td>
   <td><?php
if ($fp = @fsockopen("24.71.57.148","4000")) { echo "<img src=images/open.gif>"; } else { echo "<img src=images/closed.gif>"; }
?></td>
   <td>D2GS HU1.10 (D2Classic): </td>
   <td><?php
if ($fp = @fsockopen("69.133.108.231","4000")) { echo "<img src=images/open.gif>"; } else { echo "<img src=images/closed.gif>"; }
?></td>
 </tr>
 <tr bgcolor="#990000">
... more of the same ...
XML feed