I'm testing two versions of the same script. Each script does the same operation but they differ in how they output the result. Each script:
- Loads a local image using imagecreatefrompng()
- Adds text to image using imagettftext()
The first script outputs the final image this way:
imagepng($img, $cacheFile, $quality);
imagedestroy($img);
$fp = fopen($cacheFile, 'rb');
header("Content-Type: image/png");
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
header("Content-Length: " . filesize($cacheFile));
header('Content-Transfer-Encoding: binary');
ob_end_clean();
fpassthru($fp);
2nd script:
header('Content-Type: image/png');
imagepng($img, null, $quality);
imagedestroy($img);
Both scripts work well when I call them directly in the browser and I get the expected result. But when I use JMeter for load testing of each one, I often get a non-descriptive 500 errors in response in each script.
The error_log file, which is normally created when there are errors in the script, is not present.
How can I troubleshoot the cause of the 500 error? Is there a way to know if it's the shared hosting cutting off resources and that's why scripts fail to execute or if it's something else? How can I optimize my scripts for best performance during a heavy load?