Inprove the performance of SCode plugins of Movable Type
My friend,Fenng close the SCode (Anti-Spam Plugins) on his blog, because of this plugins consumed too much host CPU, and introduced the high load of web host. So I am trying to tuning the performance by cache the security code images, when accessing the page, if the cached image does not exist then it will call the GD library to draw the image (I think this step consumed most resource), else it will just read the content of the cached image.
I have finished the change, but I cannot test the effect, because of web clicks of my host is not high at all. Hopefully someone can tell me the performance improve.
Two changes of SCode.pm file, add a new function to return the temporary directory, and limited the security code to between 1000 and 5000, as following:
###########################
# #
# Do not modify from here #
# #
###########################
sub scode_tmpdir {
return $tmpdir;
}
if ($code>0 && $code<=$scode_maxtmp)
{
$scode = 1000 + ($scode % 4000);
open(OUTFILE,">${tmpdir}${code}");
print OUTFILE $scode;
close(OUTFILE);
}
Changes to mt-scode.cgi file, if the image are cached the read the cached image, else generate a new one and cache it. As following:
