Jump to content

Recommended Posts

I have a website that the customer can add a weekly ad (pdf) to the site as he wishes. My hosting company just sent me an email stating the following.

 

Hi,

 

Your resold account "csite" on reseller server 

Servername is running multiple instances of several php 

scripts and causing major load problem for the entire server. We have been 

monitoring this for the last couple of days. After carefully watching 

the server hardware consumption at the time when the load increases 

and server performance decreases, we have identified that your account 

is the one causing problems on the server.

 

The php scripts are running under the directory 

 

/home/csite/public_html/wkly/

 

You can see some of those processes below and their cpu usage on the entire server:

 

  PID USER  PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND

14599 csite  17  0 87200  53m  51m R  46  1.8  0:00.52 /usr/php4/bin/php /home/csite/public_html/wkly/getImage.php

14597 csite  17  0 91732  11m 4916 R  25  0.4  0:00.30 /usr/php4/bin/php /home/csite/public_html/wkly/getImage.php

14600 csite  17  0 91732  11m 4912 R  15  0.4  0:00.30 /usr/php4/bin/php /home/csite/public_html/wkly/getImage.php

14603 csite  17  0 93056  13m 4904 R    10  0.4  0:00.15 /usr/php4/bin/php /home/csite/public_html/wkly/getImage.php

14602 csite  17  0 91732  11m 4912 R    10  0.4  0:00.14 /usr/php4/bin/php /home/csite/public_html/wkly/getImage.php

 

We had no choice but to disable web access to that folder to 

stabilize the server as these processes are over loading the server. 

Please optimize your code/script to avoid these heavy resource 

consuming apache & mysql usage. You can still access the folder "wkly" using cPanel and FTP. If you need web access to work on it, provide us your IP address by visiting this page: www.myipaddress.com and we can enable web access to you as well.

If it is normal usage of the scripts/domain, I suggest you move that domain to a separate semi-dedicated account which has more resources available to run such high cpu-usage scripts.

 

Here is the code for the getImage.php

 

<?php

// required param: img

 

function string_to_number($string){

  $string = preg_replace('/[\'"]/', '', $string);

  $string = preg_replace('/[^0-9]+/', '', $string);

  $string = trim($string, '');

  $string = strtolower($string);

  return $string;}

 

$editDirectory = $_SERVER[DOCUMENT_ROOT] . '/wkly/';

$imageName = $_GET["img"];

 

$width = string_to_number($_GET['w']);

$quality = string_to_number($_GET['q']);

 

 

if(empty($imageName) || !file_exists($editDirectory.$imageName) ){ exit; }

 

 

if(empty($quality)){

$quality = 90;

}

 

// The file

$filename = $editDirectory.$imageName;

list($orig_width, $orig_height) = getimagesize($filename);

 

if(empty($width)){

$width=$orig_width;

$height=$orig_height;

}else{

 

$resize_percent = $orig_width/$width;

$height = ceil($orig_height / $resize_percent);

 

}

 

// Content type

header('Content-type: image/jpeg');

 

// Resample

$image_p = imagecreatetruecolor($width, $height);

$image = imagecreatefromjpeg($filename);

imagecopyresampled($image_p,

$image,

0,

0,

0,

0,

$width,

$height,

$orig_width,

$orig_height);

 

// Output

imagejpeg($image_p, null, $quality);

 

?>

 

 

I dont know how to optimize this script. And i cant afford to move this to a dedicated server. Any Suggestions on this

 

Thanks In Advanced.

Could also be running because people are going to the page without an image file being set

 

<?php
// required param: img

function string_to_number($string){
   $string = preg_replace('/[\'"]/', '', $string);
   $string = preg_replace('/[^0-9]+/', '', $string);
   $string = trim($string, '');
   $string = strtolower($string);
   return $string;}
if(isset($_GET['img'])){
  if(file_exists($_GET['img'])){

  $editDirectory = $_SERVER[DOCUMENT_ROOT] . '/wkly/';
  $imageName = $_GET["img"];

  $width = string_to_number($_GET['w']);
  $quality = string_to_number($_GET['q']);


  if(empty($imageName) || !file_exists($editDirectory.$imageName) ){ exit; }


  if(empty($quality)){
  $quality = 90;
  }

  // The file
  $filename = $editDirectory.$imageName;
  list($orig_width, $orig_height) = getimagesize($filename);

  if(empty($width)){
  $width=$orig_width;
  $height=$orig_height;
  }else{

  $resize_percent = $orig_width/$width;
  $height = ceil($orig_height / $resize_percent);

  }

  // Content type
  header('Content-type: image/jpeg');

  // Resample
  $image_p = imagecreatetruecolor($width, $height);
  $image = imagecreatefromjpeg($filename);
  imagecopyresampled($image_p,$image,0,0,0,0,$width,$height,$orig_width,$orig_height);

  // Output
  imagejpeg($image_p, null, $quality);
  imagedestroy($image_p);
  } else {
  echo "Image does not exist";
  }
} else {
echo "No image defined";
}
?>

 

Now it will check to see if the img is set and also check to see if it even exists also.

 

 

Ray

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.