Posiadam skrypt napisany za pomocą pakietu ImageMagick, który konwertuje tekst i obraz gif wprowadzony przez użytkownika w jeden obiekt gif i umieszcza go w serwisie. Wszystko działa poprawnie lecz przy dodwaniu większych gifów mechanizm działa bardzo długo, aż w końcu dostaję error jednak obiekt zostaje dodany:
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, webmaster@.pl and inform them of the time the error occurred, and anything you might have done that may have caused the error.
More information about this error may be available in the server error log.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
Apache/2 Server at .pl Port 80
W odpowiedzi od hostingodawcy dostałem informację, że najprawdopodobniej mam żle zoptymalizowany skrypt.
Oto Logi błedów:
[Thu Nov 01 11:33:23 2012] [error] [client 78.30.108] Script timed out
before returning headers: dodaj.php, referer:
http://--.pl/dodaj.php?co=gif
[Thu Nov 01 11:33:56 2012] [error] [client 78.30.108] File does not
exist: --.pl/public_html/500.shtml,
referer: http:/--.pl/dodaj.php?co=gif
{ if ((($_FILES["file"]["type"] == "image/gif"))) { if ($_FILES["file"]["error"] > 0) { } else { $fname); } } else { } } else { } $file = $fname; //wewnętrzny gif/////////// $max_width = 400; $max_height = 400; /////////////////////////// ///////////kolory tła://////////// ); /* Niebieski: 207 219 236 Zielony: 214 255 194 Żółty: 253 255 194 Pomarańcz: 255 233 194 Fiolet: 248 149 255 Czerwony: 255 194 194 */ $rgb = $_POST['rgb']; $r2 = $bg[$rgb][0]; $g2 = $bg[$rgb][1]; $b2 = $bg[$rgb][2]; //kolor tekstu:///////////////// $r = 67; $g = 67; $b = 67; /////////rozmiar tekstu//////// $size = 30; //plik czcionki//////////////// $font = 'Century Gothic Bold.ttf'; //////////////// $watermark= 'serwis.pl'; //watermark na dole $watermark_size = 15; //rozmiar watermarkowej czcionki /////////////// /////odstęp na dole (pod obrazkiem)///////// $space = 25; //////////////////////////////////////////// $new_h = $height+$space; /////szerokość wyniku///////// $new_w = 520; ///////////////////////////// $image = imagecreatetruecolor($new_w, $new_h+25); $color = imagecolorallocate($image, $r, $g, $b); $color_bg = imagecolorallocate($image, $r2, $g2, $b2); $y = (($new_w-$width)/2); ////odstęp od górnej krawędzi całości//// $h = 50; ///////////////////////////////////////// imagefilledrectangle($image,0,0, $new_w,$new_h+25,$color_bg); foreach ($lines as $line) { list($left,,$right,$up,,$down) = imageftbbox( $size, 0, $font, $line); $text_w = $right - $left; while($text_w>$new_w) { list($left,,$right,$up,,$down) = imageftbbox( $size, 0, $font, $line); $text_w = $right - $left; $size--; } } $size-2; foreach ($lines as $line) { list($left,,$right,$up,,$down) = imageftbbox( $size, 0, $font, $line); $text_w = $right - $left; $text_h = $up - $down; $center = ($new_w-$text_w)/2; imagettftext($image, $size, 0, $center, $h, $color, $font, $line); $h += $text_h+15; } $image2 = imagecreatetruecolor($new_w, $new_h+$h-15); imagefilledrectangle($image2,0,0, $new_w,$new_h+$h-15,$color_bg); imagecopymerge($image2, $image, 0, 0, 0, 0, $new_w, $new_h+25, 100); list($left,$down,$right) = imageftbbox( $watermark_size, 0, $font, $watermark); $text_w = $right - $left; $right_align = $new_w-$text_w-10; imagettftext($image2, $watermark_size, 0, $right_align, $new_h+$h-20, $color, $font, $watermark); imagejpeg($image2, $text_f.'.jpg'); imagedestroy($image); imagedestroy($image2); $cmd = "convert ".$file." -matte -bordercolor none -border ".$y."x".$h." ".$b.".gif"; $cmd = "convert ".$text_f.".jpg ".$b.".gif -loop 0 ".$anim.".gif"; $cmd = "convert ".$anim.".gif -coalesce -delete 0 -deconstruct -loop 0 r_".$res_img.".gif"; ///kasowanie plików pomocniczych/// $uploaddir = 'img/upload/'; $autor = $user->userInfo("id"); $wykonaj = mysql_query("INSERT INTO `shity` (`title`, `img`, `source`, `author`, `data`, `type`) VALUES ('$text', '".$uploaddir."r_".$res_img.".gif', '$zrodlo', '$autor', '$data', 'obrazek')"); } elseif ($_GET['co']=='gif') {
Co zrobić aby mechanizm działał szybciej i żeby nie pokazywał się error?