I'm in the middle of trying to optimize the php code thats used to generate the images for YASS, cleaning up code, reducing variables and whatnot. In order to help find bottlenecks, I am sending header information containing execution time and memory usage at various points in the script. I ended up graphing them in Excel too, which I have attached for anyone interested. On the graph itself, ignore the last 2 points. the second last one i used a different function to get the memory usage. The last one is the same on all graphs so that they would all be at the same scale.
I basically have 2 bottlenecks right now, the first is using imagecopy/imagecopyresized to create the background for all images. Chances are, this won't be able to be reduced too much.
The second bottleneck is calling imagepng to create the final image. As I have the code right now, the sequence of events is, imagepng is called, and the image created is written to a file. A few lines later, this file is read from disk and sent to the browser. What I want to happen, if possible, is for imagepng to be called, have the image stored in memory, sent to the browser, and then written to disk. Basically, saving from having to do a disk read.
The problem is, imagepng returns a boolean value for if the operation is successful, and not the data for the image. I have no idea if its possible to capture the output buffer to a variable or not, or if this order of events would even be possible.
Any ideas on how to improve it?
The actual code as it is now:
code:
$success = imagepng($main_image, $imgfile);
if ($success = FALSE){
die('Error creating image');
}else{
// run a SQL query
}
//output header information, and then the final image.
header('Content-type: image/png');
Header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
Header("Expires: Sat, 01 Jan 2000 01:00:00 GMT");
Header("Pragma: no-cache");
readfile($imgfile);
imagedestroy($main_image);
On a side note, why are .xls files not allowed to be uploaded?