最初の質問です、何か間違っていたらごめんなさい!
私の問題は、製品カタログに最大 18 個のサムネイル (それぞれ約 6kb) を表示する製品カタログがあることです。各サムネイルは、製品に関連する画像を検索して返すスクリプト get_db_image を呼び出します。シンプルに、ここまで。この問題は、製品カタログ ページに対して約 3 つまたは 4 つの要求が同時に行われた場合にのみ発生します。各ユーザーは 18 個のサムネイルと詳細が返されることを期待していますが、すべてのユーザーが同時にそれを行うと、メモリ不足エラーが発生します。そして時々サーバーがクラッシュします。画像を取得して表示するコードを削除し、ホスティング担当者がメモリ制限を 256M に引き上げましたが、すべて役に立ちません。私が言うことができる限り、作成したイメージを破棄していて、リクエストが行われた後、仮想メモリはゼロの分割秒に戻ります. しかし、ピーク時にはすべてのメモリが使用されているため、クラッシュが発生するため、次の画像を開始する前に各画像を取得、表示、および破棄することしか考えられませんが、それを行う方法がわかりません、しかし、おそらくより良い解決策がありますか?助けてください、私の髪を引っ張ってください。私は無駄にすることがあまりありません!
// executes the query searching for the image
$res = execPDORetRes($query, $vars);
// if there is no image, load a default
if(sizeof($res) == 0)
{
$query_parts = explode(" ", $query);
$query = "select * from ".$query_parts[3]." where id = :id";
$vars = array(':id-int' => 1);
$res = execPDORetRes($query, $vars);
}
$data = $res[0];
// create the image from the DB
$img = imagecreatefromstring($data[$name]);
$type = "image/pjpeg";
Header( "Content-type: image/pjpeg");
$width = imagesx($img);
$height = imagesy($img);
// if the image is too big
if($size_w != $width || $size_h != $height)
{
// set widths and heights
if ($width <= $size_w)
{
$new_w = $width;
$new_h = $height;
}
else
{
$new_w = $size_w;
$new_h = $size_h;
}
// create a new image of the specified width and height
$new_img = imagecreatetruecolor($new_w,$new_h);
// resize the original
imagecopyresized($new_img,$img,0,0,0,0,$new_w,$new_h,$width,$height);
// determine image type and send it to the client
imagejpeg($new_img,"","80");
// clear the image from memory
imagedestroy($new_img);
imagedestroy($img);
unset($width, $height, $new_h, $new_w, $new_img, $img);
}
else
{
// if the image is smaller than or the right size
// determine image type and send it to the client
imagejpeg($img,"","80");
// clear the image from memory
imagedestroy($img);
unset($width, $height, $img);
}
ob_flush();
助けてくれてありがとう。