Prime spirals are always fun to watch(not...) and pretty brain hurting to implement. After 2 trials, Chao successfully created by far the fastest PHP prime spiral generator(for a 200*200 image, it's 20 times faster than the original)...
I challenge anyone to write a script that beat this one's speed
http://webdevlogs.com/2007/05/07/the-most-optimal-php-prime-spiral-generator-yet

$size = 500;
$prime = esprime($size*$size);
$image = imagecreate($size,$size);
imagecolorallocate($image,255,255,255);
$color = imagecolorallocate($image,0,0,0);
$size2=$size/2;
$n = 2;$t = true;$sn=4;
$midu=2;$midl=4;$midd=6;$midr=8;
while($n<$size){
if($prime[0]<=$sn){
$p = array_shift($prime);
if($t){//even
if($p <= $sn-$n){
$x = $n/2;
$y = $midu - $p;
}else{
$x = $midl -$p;
$y = -$n/2;
}
}else{//odd
if($p <= $sn-$n){
$x = (-$n/2)+0.5;
$y = $p - $midd;
}else{
$x = $p - $midr;
$y = ($n/2)-0.5;
}
}
imagesetpixel($image,$x+$size2,$y+$size2,$color);
}else{
++$n;
$sn = $n * $n;
$t = !$t;
if($t){
$midu = $sn-$n*1.5+1;
$midl = $sn-$n*0.5+1;
}else{
$midd = $sn-$n*1.5+1.5;
$midr = $sn-$n*0.5+0.5;
}
}
}
header("Content-type: image/png");
imagepng($image);