PHP Script freezes ftp service? True or not?
Posted: Mon Dec 01, 2008 7:48 am
There are recently some problems with a client's server (Windows/PHP5), somehow the ftp service freezes from time to time,
ini_set looks a bit suspicious here to me, but I doubt it might be the problem as without this script being executed, the service still freezes from time to time and also I tested the script in 3 other servers (2 Linux/PHP 5, 1 Windows/PHP4) and it works fine.
However here is the script: (sorry warnings are in Greek)
I just need to get the possibility of script error out of my head so I can move on with the other problems,
I also inspected their php ini and saw that they have memory_limit set to 128M. Could this be the problem? I suggested they set it to 32M.
They also have installed some extensions (including:
GD library http://www.libgd.org/Downloads
BZ library http://www.bzip.org/
cURL lib http://curl.haxx.se/
mCrypt http://mcrypt.sourceforge.net/) lately which was when the server started having this problem.
So my possible problems would be:
PHP Memory Limit,
Software Problem (ftp/IIS),
PHP Script problem (upload script),
PHP Extension problem,
Other, software/hardware problem etc.
ini_set looks a bit suspicious here to me, but I doubt it might be the problem as without this script being executed, the service still freezes from time to time and also I tested the script in 3 other servers (2 Linux/PHP 5, 1 Windows/PHP4) and it works fine.
However here is the script: (sorry warnings are in Greek)
Code: Select all
<?
$upload_success=0;
/* PDF UPLOADING */
//change upload session lifetime
ini_set("session.gc_maxlifetime","50800");
//Maximum file size.
$MAX_SIZE = 50000000;
$max_kbs = $MAX_SIZE/1000;
$max_width = 5000;
$max_height = 5000;
//valid extensions
$FILE_EXTS = array('.pdf');
$file_extensions='.pdf';
switch($_GET['file']){
case 'geturl':
// UPLOAD FILE
//Get server paths
$site_name = $_SERVER['HTTP_HOST'];
$url_dir = "http://".$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']);
$url_this = "http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
$upload_dir = "../uploads/cover/";
$upload_url = $url_dir."../uploads/cover/";
//get file name
$file_name = $_FILES['userfile']['name'];
$temp_name = $_FILES['userfile']['tmp_name'];
$file_size = $_FILES['userfile']['size'];
$file_path = $upload_dir.$file_name;
list($width, $height, $type, $attr) = getimagesize($temp_name);
$file_ext = strtolower(substr($file_name,strrpos($file_name,".")));
$file_size_kbs=$file_size/1000;
//replace illegal characters
$file_name = str_replace("\\","",$file_name);
$file_name = str_replace("'","",$file_name);
//Check if file exists
$file_to_check="../uploads/cover/$file_name";
//Check file name
if ($file_name == "")
{
echo "<div id='notice' ><div style='background-color:#FFFF66;width:520px;height:20px;text-indent:4px;color:#333333'><img src='alert.png' alt='alert' /><b> ??? ?????????? ?????? PDF</b></div></div>";
}
else
{
//Check file name length
if (!strlen (basename(($file_name))) =='cover')
{
echo "<div id='notice' ><div style='background-color:#FFFF66;width:520px;height:20px;text-indent:4px;color:#333333'><img src='alert.png' alt='alert' /><b> ?? ?????? PDF ?????? ?? ?????????? <b>cover.pdf</b>!</b></div></div>";
}
else
{
//File Dimensions Check
if( $width > $max_width || $height > $max_height)
{
echo "<div id='notice' ><div style='background-color:#FFFF66;width:520px;height:20px;text-indent:4px;color:#333333'><img src='alert.png' alt='alert' /><b> ?? ?????????? ??? PDF ????? ??????????? ??? ?? ???????????? ($max_width x $max_height)</b></div></div>";
}
else
{
//File Size Check
if( $file_size > $MAX_SIZE)
{
echo "<div id='notice' ><div style='background-color:#FFFF66;width:520px;height:20px;text-indent:4px;color:#333333'><img src='alert.png' alt='alert' /><b> ?? ??????? ??? ??????? ($file_size_kbs Kbs) ????? ?????????? ??? ?? ???????????? ($max_kbs Kbs)</b></div></div>";
}
else
{
//File type Check
if (!in_array($file_ext, $FILE_EXTS))
{
echo "<div id='notice' ><div style='background-color:#FFFF66;width:520px;height:20px;text-indent:4px;color:#333333'><img src='alert.png' alt='alert' /><b> ????? ? ????? ??????? ??? ????? PDF.</b></div></div>";
}
else
{
//fileupload
$result = move_uploaded_file($temp_name, $file_path);
if ($result==1)
{
echo "<div id='notice' ><div style='background-color:#FFFF66;width:520px;height:20px;text-indent:4px;color:#333333'><img src='alert.png' alt='alert' /><b> ?? ?????? PDF ??????? ?? ????????!</b>
</center><br/></p>";
$upload_success=$upload_success+1;
}
else
{
echo "<div id='notice' ><div style='background-color:#FFFF66;width:520px;height:20px;text-indent:4px;color:#333333'><img src='alert.png' alt='alert' /><b> ?? ?????? PDF ??? ??????? ?? ?????? ??? server! </b></div></div>";
exit;
}
}
}
}
}
}
break;
default:
}
echo "<br/>";
/* JPG UPLOADING */
//change upload session lifetime
ini_set("session.gc_maxlifetime","50800");
//Maximum file size.
$MAX_SIZE = 5000000;
$max_kbs = $MAX_SIZE/1000;
$max_width = 418;
$max_height = 528;
//valid extensions
$FILE_EXTS = array('.jpg');
$file_extensions='.jpg';
switch($_GET['file']){
case 'geturl':
// UPLOAD FILE
//Get server paths
$site_name = $_SERVER['HTTP_HOST'];
$url_dir = "http://".$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']);
$url_this = "http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
$upload_dir = "../uploads/cover/";
$upload_url = $url_dir."../uploads/cover/";
//get file name
$file_name = $_FILES['userfile2']['name'];
$temp_name = $_FILES['userfile2']['tmp_name'];
$file_size = $_FILES['userfile2']['size'];
$file_path = $upload_dir.$file_name;
list($width, $height, $type, $attr) = getimagesize($temp_name);
$file_ext = strtolower(substr($file_name,strrpos($file_name,".")));
$file_size_kbs=$file_size/1000;
//replace illegal characters
$file_name = str_replace("\\","",$file_name);
$file_name = str_replace("'","",$file_name);
//Check if file exists
$file_to_check="../uploads/cover/$file_name";
//Check file name
if ($file_name == "")
{
echo "<div id='notice' ><div style='background-color:#FFFF66;width:520px;height:20px;text-indent:4px;color:#333333'><img src='alert.png' alt='alert' /><b> ??? ?????????? ?????? JPG</b></div></div>";
}
else
{
//Check file name length
if (!strlen (basename(($file_name))) =='cover')
{
echo "<div id='notice' ><div style='background-color:#FFFF66;width:520px;height:20px;text-indent:4px;color:#333333'><img src='alert.png' alt='alert' /><b> ?? ?????? JPG ?????? ?? ?????????? <b>cover.jpg</b>!</b></div></div>";
}
else
{
//File Dimensions Check
if( $width > $max_width || $height > $max_height)
{
echo "<div id='notice' ><div style='background-color:#FFFF66;width:520px;height:20px;text-indent:4px;color:#333333'><img src='alert.png' alt='alert' /><b> ?? ?????????? ??? ??????? ????? ??????????? ??? ?? ???????????? ($max_width x $max_height)</b></div></div>";
}
else
{
//File Size Check
if( $file_size > $MAX_SIZE)
{
echo "<div id='notice' ><div style='background-color:#FFFF66;width:520px;height:20px;text-indent:4px;color:#333333'><img src='alert.png' alt='alert' /><b> ?? ??????? ??? ??????? ($file_size_kbs Kbs) ????? ?????????? ??? ?? ???????????? ($max_kbs Kbs)</b></div></div>";
}
else
{
//File type Check
if (!in_array($file_ext, $FILE_EXTS))
{
echo "<div id='notice' ><div style='background-color:#FFFF66;width:520px;height:20px;text-indent:4px;color:#333333'><img src='alert.png' alt='alert' /><b> ????? ? ????? ??????? ??? ????? JPG.</b></div></div>";
}
else
{
//fileupload
$result = move_uploaded_file($temp_name, $file_path);
if ($result==1)
{
echo "<div id='notice' ><div style='background-color:#FFFF66;width:520px;height:20px;text-indent:4px;color:#333333'><img src='alert.png' alt='alert' /><b> ?? ?????? JPG ??????? ?? ????????!</b>
</center><br/></p>";
$upload_success=$upload_success+1;
}
else
{
echo "<div id='notice' ><div style='background-color:#FFFF66;width:520px;height:20px;text-indent:4px;color:#333333'><img src='alert.png' alt='alert' /><b> ?? ?????? JPG ??? ??????? ?? ?????? ??? server! </b></div></div>";
exit;
}
}
}
}
}
}
break;
default:
}
echo "<center>";
//output success or not
if ($upload_success>1 && $_GET['action']=='upload')
{
echo "<br/><div id='notice' ><div style='background-color:#298000;width:520px;height:20px;text-indent:4px;color:#333333'><img src='alert.png' alt='alert' /><b> T? update ??? ????????? ????????????????! </b></div></div><br/>";
}
if ($upload_success==1 && $_GET['action']=='upload')
{
echo "<br/><div id='notice' ><div style='background-color:#FFFF66;width:520px;height:20px;text-indent:4px;color:#333333'><img src='alert.png' alt='alert' /><b> T? update ??? ????????? ??? ???? ??????? ????????! </b></div></div><br/>";
}
if ($upload_success<1 && $_GET['action']=='upload')
{
echo "<br/><div id='notice' ><div style='background-color:#FF5151;width:520px;height:20px;text-indent:4px;color:#333333'><img src='alert.png' alt='alert' /><b> T? update ??? ????????? ??? ???? ????????! </b></div></div><br/>";
}
echo "</center>";
?>I also inspected their php ini and saw that they have memory_limit set to 128M. Could this be the problem? I suggested they set it to 32M.
They also have installed some extensions (including:
GD library http://www.libgd.org/Downloads
BZ library http://www.bzip.org/
cURL lib http://curl.haxx.se/
mCrypt http://mcrypt.sourceforge.net/) lately which was when the server started having this problem.
So my possible problems would be:
PHP Memory Limit,
Software Problem (ftp/IIS),
PHP Script problem (upload script),
PHP Extension problem,
Other, software/hardware problem etc.