|
 323.4 Кб |
|
| Есть у меня скрипт для автоматического добавления файлов и папок на срвер.
Ранее все работало, а теперь mysql server has gone away .
<?php
require "config.php";
mysql_connect($SERVER,$USER,$PASSWD);
mysql_select_db($DB);
@mysql_query("SET NAMES cp1251");
$indir = $_POST['indir'];
$dirname = $_POST['dirname'];
$stl = $_GET['stl'];
if(!$stl) { $stl = 60; }
set_time_limit(9900);
function mime($file) {
$filename = basename($file);
$str = strlen($file);
$strm = $str-4;
$sub = substr($file,$strm,$str);
$sub = strtolower($sub);
$mime['.mp3'] = "audio/mp3";
$mime['.png'] = "image/png";
$mime['.jpg'] = "image/jpeg";
$mime['.gif'] = "image/gif";
if(IsSet($mime[$sub])) { $type = $mime[$sub]; }
return $type;
}
?>
<form action="insrc.php" method="post">
set_time_limit(<input type="text" name="stl" value="<?php echo $stl; ?>" size="5">);<br />
indir : <input type="text" name="indir" size="5" value="<?php echo $indir; ?>"> <br />
dirname: <input type="text" name="dirname" size="120" value="<?php echo $dirname; ?>"> <br />
<input type="submit">
</form>
<?php
if(($indir) AND ($dirname))
{
function insrc($indir,$dirname)
{
$fd = opendir($dirname); $index = 0;
while(($file = readdir($fd)) !== false)
{
if($file != "." && $file != "..")
{
if(is_dir("$dirname/$file"))
{
$query = mysql_query("SELECT * FROM `folders` ORDER BY `id` DESC LIMIT 1;");
$fetch = mysql_fetch_array($query);
$iid = $fetch[id];
$iid = $iid+1;
$foldername = str_replace("/","",$file);
$foldername = str_replace("zt312","",$foldername);
$query = mysql_query("SELECT * FROM `folders` WHERE `id`='$indir';");
$fetch = mysql_fetch_array($query);
$level = $fetch[level];
$level = $level+1;
$like = $indir; $index = $index+1; $foldername = mysql_escape_string($foldername);
echo "<font color=\"green\"> INSERT INTO `folders`(`id`,`foldername`,`level`,`like`) VALUES('$iid','$foldername','$level','$like'); </font><br />\r\n";
mysql_query("INSERT INTO `folders`(`id`,`foldername`,`level`,`like`) VALUES('$iid','$foldername','$level','$like');"); echo mysql_error();
insrc($iid,"$dirname/$file");
// $indir = null;
} else {
$query = mysql_query("SELECT * FROM `files` ORDER BY `id` DESC LIMIT 1;");
$fetch = mysql_fetch_array($query);
$iid = $fetch[id];
$iid = $iid+1;
$filename = $file; $flike = $indir; $filename = mysql_escape_string($filename);
$fdo = fopen("$dirname/$file","r");
$bufer = fread($fdo,filesize("$dirname/$file"));
$size = filesize("$dirname/$file"); if($size > 61000000) { $size = "null"; $bufer = "unknown file. - file size"; sleep(2); }
$type = mime($filename);
fclose($fdo);
echo "<font color=\"blue\"> INSERT INTO `file`(`id`,`filename`,`usersload`,`like`,`count`,`file`,`size`,`type`) VALUES('$iid','$filename','0','$flike','0','localhost','$size','$type'); </font><br />\r\n";
mysql_query("INSERT INTO `files`(`id`,`filename`,`usersload`,`like`,`count`,`file`,`size`,`type`) VALUES('$iid','$filename','0','$flike','0','localhost','$size','$type');"); echo mysql_error();
$bufer = mysql_escape_string($bufer);
mysql_query("INSERT INTO `blob_files`(`id`,`file`) VALUES('$iid','$bufer');");
} // is_file;
} // is not;
} //while;
} //insrc;
insrc($indir,$dirname);
}
?>
|
может потому что в базе данных больше 150 гб файлов
результат в картинке вложеной | |
|
|
|
|
|
|
|
для: toproot
(17.01.2010 в 14:32)
| | You can also get these errors if you send a query to the server that is incorrect or too large. If mysqld receives a packet that is too large or out of order, it assumes that something has gone wrong with the client and closes the connection. If you need big queries (for example, if you are working with big BLOB columns), you can increase the query limit by setting the server's max_allowed_packet variable, which has a default value of 1MB. You may also need to increase the maximum packet size on the client end. More information on setting the packet size is given in Section B.1.2.10, “Packet too large”.
>скрипт для автоматического добавления файлов и папок на срвер
Больше похоже на скрипт для крэш-тестирования сервера базы данных
, думаю это из-за
$bufer = fread($fdo,filesize("$dirname/$file"));
mysql_query("INSERT INTO `blob_files`(`id`,`file`) VALUES('$iid','$bufer');"); | |
|
|
|
|
|
|
|
для: heed
(17.01.2010 в 15:28)
| | Все спасибо, поставил 60 метров packet и все окей | |
|
|
|
|