Jump to content

php locking up the server processes


garethhall

Recommended Posts

Hello guys my php seems to crash the server sometimes only. I have a multiple image uploader and it works fine for say 60% of the time, sometimes I can upload 300 images without any problems. But other times it fails after 10 or 20 images.

 

The error is http 500 caused by going for me process limit. I think the problem is with imagemagick????

And I am not getting my email alert!

 

Here is what the system does. Its a photographers website (To sell images).

1.It can upload multiple images in a que (2 at a time, NOTE i tried one at a time same fault). It has a progressbar I use jquery and uploadify to accomplish this.

2. Take the high res image (300dpi) and move it the high res folder

3. Takes high res image and makes a thumbnail in thumbnail folder

4. Takes high res image and makes a watermarked version for preview watermark folder.

5. Lastly insert the data into the DB.

 

Can anyone see anything wrong with my code?

<?php
require_once('../../Connections/admin.php');
session_start();	

$albumID = $_POST["aid"];
$clientID = $_POST["cid"];

if (!empty($_FILES) && !empty($albumID) && !empty($clientID)) {
$tempFile = $_FILES['Filedata']['tmp_name'];
$originalName = $_FILES['Filedata']['name'];

$targetPath = '../smartP/HRimg/';
$ext = pathinfo($_FILES['Filedata']['name'], PATHINFO_EXTENSION);  // file extension
$ext = strtolower($ext);
$fileName = uniqid("").".".$ext;  // create unique file name
$targetFile =  str_replace('//','/',$targetPath) . $fileName;

if(!move_uploaded_file($tempFile,$targetFile)){
	mail("[email protected]","Bug Move File","Traget file: ".$targetFile." OR name: ".$originalName,"From: [email protected]" . "\r\n");
	exit();
}else{
	//$originalPath = $basePath . '/smartP/HRimg/' . $fileName;
$originalPath =   '../smartP/HRimg/' . $fileName;

// ==================================== create thumbnail =============================================

// Maximum image width
$max_width = "128";
// Maximum image height
$max_height = "128";
//$thumbnailPath = $basePath . 'smartP/thumb/' . $fileName;
$thumbnailPath = '../smartP/thumb/' . $fileName;

// imagemagic functions
exec("convert $originalPath -resize {$max_width}x{$max_height}\> $thumbnailPath");// Resize to tumbnail dimensions
exec("convert -density 72 $thumbnailPath $thumbnailPath");// change to 72 dpi
exec("convert -quality 60% $thumbnailPath $thumbnailPath");// change quality.

// ==================================== create watermark ===================================================

$temp = '../smartP/photos/' . $fileName;
$width = "800";
$height = "600";
$watermark = '../includes/waterMark.png'; 
exec("convert $originalPath -resize {$width}x{$height}\> $temp");
exec("composite -watermark 10% -gravity south $watermark $temp $temp");
exec("convert -density 72 $temp $temp");	
exec("convert -quality 65% $temp $temp");

mysql_select_db($database_admin, $admin);

// select all clients belonting to group
$sel = "SELECT clientID FROM clients WHERE clientGroup = '".$clientID."' OR clientID = '".$clientID."'";
$rss = mysql_query($sel,$admin);
while($rws = mysql_fetch_assoc($rss)){

	// insert group photos to client and group
	$ins = "INSERT INTO photos (photoID, photoName, originalName, photoDate, albumId, clientId, saleState) VALUES ('','".$fileName."','".$originalName."',CURDATE(),".$albumID.",".$rws['clientID'].",1)";
	mysql_query($ins,$admin);
}
mysql_free_result($rss);
}

echo "1";
}

?>

Link to comment
https://forums.phpfreaks.com/topic/176919-php-locking-up-the-server-processes/
Share on other sites

what do you mean by http server

 

Um, the http server. Likely to be Apache seeing as your using Linux.

 

I would try and remove the process of resizing and watermarking away from the process of uploading. The former can be done server side once the images are recieved and without any need for client interaction.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.