Why is my code so slow?
Submitted by phrax on Thu, 2004-10-28 15:13.
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 ...