سؤال

My code converts PDF file pages into JPEG images once uploaded, and it all goes fine when working on light PDFs (not many images and effects, while the number of pages is no more than 40-50 on average). But when file is heavier, I get a "500 Internal Error". The PDF has been uploaded and pages have been converted up to the break point.

My code:

$foldername = str_replace('.','',preg_replace('/\s+/', '', microtime()));
mkdir("./mag_thumbs/".$foldername, 0755, TRUE);
try
{
    $compression_type = Imagick::COMPRESSION_JPEG; 
    $im = new imagick();
    $im->setResolution(250,250);
    $im->readimage($pdf_path); 
    $pdf_count = $im->getNumberImages();
    $im->setImageFormat('jpg');
    $im->flattenImages();    
    $im->setImageCompression($compression_type); 
    $im->setImageCompressionQuality(40); 
    $im->writeImages('./mag_thumbs/'.$foldername.'/page.jpg',true); 
    $im->clear(); 
    $im->destroy();
}
catch(Exception $e){ /* SOME TROUBLESHOOTING CODE */ }

Am I supposed to expand servers' time out? Any other better solution?

هل كانت مفيدة؟

المحلول

Enter these lines above your code:

ini_set('max_execution_time', 10000);//you can change this limit
ini_set("memory_limit", "6400M");//you can change this limit
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top