Something in this PHP code is causing the webserver to be unresponsive |
Author: |
Message: |
MeEtc
Patchou's look-alike
In the Shadow Gallery once again
Posts: 2200 Reputation: 60
38 / /
Joined: Nov 2004
Status: Away
|
O.P. Something in this PHP code is causing the webserver to be unresponsive
Well, as the title says..
It's a part of the YASS image generator that seems to be causing extreme load on the server. When an image that contains emoticons is attempted to be rendered, things go downhill. I can't load any page on the server,and logging into FTP is next to impossible. commenting the following block of code, allows loading return to normal once more. anyone want to take a stab as to what's happening?
code: $baseheight = imagettfbboxext($nicksize, 'resources/font/'.$imgitem[$imgdata['nick_font']], '|');
if ($baseheight['height'] < 19)
$emotesize = $baseheight['height'];
else
$emotesize = 19;
$spacewidth = imagettfbboxext($nicksize, 'resources/font/'.$imgitem[$imgdata['nick_font']], ' ');
$spacer = ' ';
$i=0;
while(strlen($spacer)*$spacewidth['width'] < $emotesize && $i++ < 30)
$spacer .= ' ';
$emoteoffsetx = floor(abs((strlen($spacer)*$spacewidth['width']-$emotesize)/2+1));
$emoteoffsety = floor(abs(($baseheight['height']-$emotesize)/2));
$i=0;
while ($i <= count($smileys_from)){
$pos = strpos($strUsername, $smileys_from[$i]);
if ($pos !== FALSE){
$imgEmote = imagecreatefrompng('resources/emotes/' . $smileys_to[$i] . '.png');
$emotepos = imagettfbboxext($nicksize, 'resources/font/'.$imgitem[$imgdata['nick_font']], substr($strUsername, 0, $pos));
imagecopyresized($imgBack, $imgEmote, $emotepos[4] + $imgdata['nick_x'] + $emoteoffsetx, $emotepos[7] + $imgdata['nick_y'] + $emoteoffsety, 0, 0, $emotesize, $emotesize, imagesx($imgEmote), imagesy($imgEmote));
$strUsername = str_replace_once($smileys_from[$i], $spacer, $strUsername);
imagedestroy($imgEmote);
} else {
$i++;
}
}
I cannot hear you. There is a banana in my ear.
|
|
11-27-2007 03:29 AM |
|
|
hmaster
Senior Member
Posts: 716 Reputation: 24
33 / /
Joined: Nov 2004
|
RE: Something in this PHP code is causing the webserver to be unresponsive
$baseheight = imagettfbboxext($nicksize, 'resources/font/'.$imgitem[$imgdata['nick_font']], '|');
if ($baseheight['height'] < 19){
$emotesize = $baseheight['height'];
} else {
$emotesize = 19;
}
$spacewidth = imagettfbboxext($nicksize, 'resources/font/'.$imgitem[$imgdata['nick_font']], ' ');
$spacer = ' ';
$i=0;
while(strlen($spacer)*$spacewidth['width'] < $emotesize && $i++ < 30) {
$spacer .= ' ';
$emoteoffsetx = floor(abs((strlen($spacer)*$spacewidth['width']-$emotesize)/2+1));
$emoteoffsety = floor(abs(($baseheight['height']-$emotesize)/2));
}
$i=0;
while ($i <= count($smileys_from)){
$pos = strpos($strUsername, $smileys_from[$i]);
if ($pos !== FALSE){
$imgEmote = imagecreatefrompng('resources/emotes/' . $smileys_to[$i] . '.png');
$emotepos = imagettfbboxext($nicksize, 'resources/font/'.$imgitem[$imgdata['nick_font']], substr($strUsername, 0, $pos));
imagecopyresized($imgBack, $imgEmote, $emotepos[4] + $imgdata['nick_x'] + $emoteoffsetx, $emotepos[7] + $imgdata['nick_y'] + $emoteoffsety, 0, 0, $emotesize, $emotesize, imagesx($imgEmote), imagesy($imgEmote));
$strUsername = str_replace_once($smileys_from[$i], $spacer, $strUsername);
imagedestroy($imgEmote);
} else {
$i++;
}
}[/code]
I think it's just the while loop continuing when it should stop?
|
|
11-27-2007 08:07 AM |
|
|
mynetx
Skinning Contest Winner
Microsoft insider
Posts: 1175 Reputation: 33
37 / /
Joined: Jul 2007
|
RE: Something in this PHP code is causing the webserver to be unresponsive
$i++;
isn't executed when a smilie was found, only ("else") when no smilie was found.
code: $i=0;
while ($i <= count($smileys_from)){
$pos = strpos($strUsername, $smileys_from[$i]);
if ($pos !== FALSE){
$imgEmote = imagecreatefrompng('resources/emotes/' . $smileys_to[$i] . '.png');
$emotepos = imagettfbboxext($nicksize, 'resources/font/'.$imgitem[$imgdata['nick_font']], substr($strUsername, 0, $pos));
imagecopyresized($imgBack, $imgEmote, $emotepos[4] + $imgdata['nick_x'] + $emoteoffsetx, $emotepos[7] + $imgdata['nick_y'] + $emoteoffsety, 0, 0, $emotesize, $emotesize, imagesx($imgEmote), imagesy($imgEmote));
$strUsername = str_replace_once($smileys_from[$i], $spacer, $strUsername);
imagedestroy($imgEmote);
}
$i++;
}
|
|
11-27-2007 08:27 AM |
|
|
WDZ
Former Admin
Posts: 7106 Reputation: 107
– / /
Joined: Mar 2002
|
RE: Something in this PHP code is causing the webserver to be unresponsive
hmaster: Adding those curly brackets makes no difference, they're optional.
mynetx: I think that's by design... it allows for multiple instances of the same smilie.
|
|
11-27-2007 08:37 AM |
|
|
MeEtc
Patchou's look-alike
In the Shadow Gallery once again
Posts: 2200 Reputation: 60
38 / /
Joined: Nov 2004
Status: Away
|
O.P. RE: Something in this PHP code is causing the webserver to be unresponsive
braces are only needed if there is being more than one line being executed, as a group of code. And yes, it is by design. if I replaced the 'while' with a 'for' only the first occurrence of each icon would be displayed.
so, does anyone have any good suggestions to offer?
I cannot hear you. There is a banana in my ear.
|
|
11-27-2007 09:36 PM |
|
|
WDZ
Former Admin
Posts: 7106 Reputation: 107
– / /
Joined: Mar 2002
|
RE: Something in this PHP code is causing the webserver to be unresponsive
I'd just throw some temporary debug code in there to find out exactly what's going on. Track the values of all relevant variables, count the total number of iterations made by the loop, and dump the info to a file.
|
|
11-27-2007 10:04 PM |
|
|
|
|