The OpenNET Project / Index page

[ новости /+++ | форум | теги | ]

форумы  помощь  поиск  регистрация  майллист  вход/выход  слежка  RSS
"Быстрота занесения данных из xml файла в MySQL"
Вариант для распечатки  
Пред. тема | След. тема 
Форумы WEB технологии (Public)
Изначальное сообщение [ Отслеживать ]

"Быстрота занесения данных из xml файла в MySQL"  
Сообщение от cascas email(??) on 20-Фев-08, 12:25 
Добрый день

Поставил SLES 10 на сервер и заметил такую проблему

Есть php скрипт который читает xml файл (30Мегов) и заносит информацию в базу Mysql
Так вот, когда он даботает процессор не загружается вообще и очень медленно идет добавление.

Раньше стоял FreeBSD и вся это связка грузила проц на 100%

В чем может быть проблемма?

ЗЫ apache mysql and php были установленны с диска

Высказать мнение | Ответить | Правка | Cообщить модератору

 Оглавление

Сообщения по теме [Сортировка по времени | RSS]


1. "Быстрота занесения данных из xml файла в MySQL"  
Сообщение от angra (ok) on 20-Фев-08, 14:00 
Проблема в том что вы даже не сказали чего вы хотите, может добиться опять 100% загрузки проца? Кроме того очень тяжело давать какие либо советы и объяснения по работе программы не имея ее кода.
Высказать мнение | Ответить | Правка | Наверх | Cообщить модератору

2. "Быстрота занесения данных из xml файла в MySQL"  
Сообщение от cascas email(??) on 20-Фев-08, 14:23 
>Проблема в том что вы даже не сказали чего вы хотите, может
>добиться опять 100% загрузки проца? Кроме того очень тяжело давать какие
>либо советы и объяснения по работе программы не имея ее кода.
>

Вы думаете это проблемма кода?

$currentTag="";
            $currentAttribs="";

            global $num, $price, $categoryId_b, $picture, $author, $name_b, $publisher, $year, $ISBN, $pages, $description_b, $array_pic, $pathtoshop;
            $num=0;
            $price=0;
            $categoryId_b=0;
            $picture="";
            $author="";
            $name_b="";
            $publisher="";
            $year="";
            $ISBN="";
            $pages="";
            $description_b="";
            $pathtoshop="products_pictures";

            $link = mysql_connect($hostname, $username, $password)
                    or die("Could not connect: " . mysql_error());
            print ("Connected to MySQL successfully
");
//              mysql_query("SET NAMES utf8") or die("Invalid: ".mysql_error());

            mysql_select_db($db, $link) or die ('Can\'t use $db : '.mysql_error());

            function startElement($parser, $name, $attribs){
                    global $currentTag, $currentAttribs, $categoryID, $parent, $product_code, $name_b, $picture;
                    $currentTag=$name;
                    $currentAttribs=$attribs;

                    switch ($name){
                            case "name":
                                  $name_b="";
                                  break;
                            case "picture":
                                  $picture="";
                                  break;
                            case "category":
                                  while (list ($key, $value)=each ($attribs)){
                                          if ($key=="id"){
                                                  $categoryID=$value;
                                          }else{
                                                  $parent=$value;
                                          }
                                  }
                                  break;
                            case "offer":
                                  while (list ($key, $value)=each ($attribs)){
                                          if ($key=="id"){
                                                  $product_code=$value;
                                          }else{
                                                  $type=$value;
                                          }
                                  }
                                  break;
                            default:
                                    break;
                    }

            }

            function endElement ($parser, $name){
                    global $currentTag, $categoryID, $parent, $product_code, $num, $price, $categoryId_b, $picture, $author, $name_b, $publisher, $year, $ISBN, $pages, $description_b, $array_pic, $pathtoshop;

                    switch ($name){
                            case "picture":
                                  $array_pic=split('[/]',$picture);

                                echo ("$array_pic[5]
");
                                echo ("picture: $picture
");

                                  if (!(file_exists("picture/$array_pic[5]"))){
                                        echo ("$array_pic[2]
");

                                        copy ("$picture", "picture/$array_pic[5]");
                                        echo ("download - $array_pic[5]
");
                                        copy ("picture/$array_pic[5]", "$pathtoshop/$array_pic[5]");
                                          echo ("copy - $array_pic[5]
");
                                  }else{
                                        echo ("exist - $array_pic[5]
");
                                  }
                                $query3 = "INSERT INTO SS_product_pictures (photoID,productID,filename,thumbnail,enlarged) VALUES ($categoryID+1,$categoryID+1,'$array_pic[5]','$array_pic[5]','$array_pic[5]')";
                                  $result3 = mysql_query($query3);
                                  if ($result3=0){
//                                      echo ($categoryID+1);
//edit
//                                      echo ($array_pic[5]);
                                      die("Query failed : " . mysql_error());
                                }
//                                      echo $categoryID+1;

                                  break;
                            case "offer":
                                $query3 = "INSERT INTO SS_product_pictures (photoID,productID,filename,thumbnail,enlarged) VALUES ($product_code,$product_code,'$array_pic[5]','$array_pic[5]','$array_pic[5]')";
                                  $result3 = mysql_query($query3);
                                  if ($result3=0){
//edit
                                      echo ($product_code);
//edit
                                      echo ($array_pic[5]);
                                      die("Query failed : " . mysql_error());
                                }

                                $query2 = "INSERT INTO SS_products (categoryID,name,description,Price,in_stock,enabled,brief_description,product_code,default_picture,meta_description,meta_keywords) VALUES ($categoryId_b+1,'$name_b','<strong>Publisher:</strong> $publisher,
<strong>Author(s):</strong> $author,
<strong>Year:</strong> $year,
<strong>Pages:</strong> $pages,
<strong>ISBN:</strong> $ISBN

<strong>Description:</strong>
$description_b',$price,100,1,'Publisher: $publisher,
Author(s): $author,
Year: $year,
Pages: $pages,
ISBN: $ISBN',$product_code,$product_code,'$name_b - Publisher: $publisher, Author(s): $author, Year: $year, Pages: $pages, ISBN: $ISBN, Description: $description_b','$name_b - Publisher: $publisher, Author(s): $author, Year: $year, Pages: $pages, ISBN: $ISBN, Description: $description_b')";
                                $result2 = mysql_query($query2);
                                  if ($result2=0){
                                      die("Query failed : " . mysql_error());
                                  }
                                  $num++;

                                  $name_b="";
                                  $description_b="";
                                  break;
                            default:
                                      break;
                    }

                    $currentTag="";
                    $currentAttribs="";
            }

            function characterData ($parser, $data){
                    global $currentTag, $categoryID, $parent, $product_code, $num, $price, $categoryId_b, $picture, $author, $name_b, $publisher, $year, $ISBN, $pages, $description_b, $array_pic, $pathtoshop;

                    switch ($currentTag){
                            case "category":

                                $query = "INSERT INTO SS_categories (categoryID,name,parent,meta_description,meta_keywords) VALUES ($categoryID+1,'$data',$parent+1,'$data','$data')";
                                  $result = mysql_query($query);
                                  if ($result=0){
                                      echo ($data);
                                      echo ($categoryID);
                                      echo ($parent);
                                      die("Query failed : " . mysql_error());
                                  }
                                  break;
                            case "price":
                                  $price=$data;
                                  break;
                            case "categoryId":
                                  $categoryId_b=$data;
                                  break;
                            case "picture":
                                  $picture.=$data;
                                  break;
                            case "author":
                                  $author=$data;
                                  break;
                            case "name":
                                $name_b.=$data;
                                  break;
                            case "publisher":
                                  $publisher=$data;
                                  break;
                            case "year":
                                  $year=$data;
                                  break;
                            case "ISBN":
                                  $ISBN=$data;
                                  break;
                            case "pages":
                                  $pages=$data;
                                  $query2 = "INSERT INTO SS_products VALUES ('',$categoryId_b,'$name_b','������������: $publisher,
�����(�): $author,
���: $year,
�������: $pages,
ISBN: $ISBN','',$price,'$array_pic[2]','100',NULL,'','','$array_pic[2]',1,'������������: $publisher,
�����(�): $author,
���: $year,
�������: $pages,
ISBN: $ISBN','',$product_code)";
                                  $result2 = mysql_query($query2);
                                  if ($result2=0){
                                      echo ($name);
                                      echo ($categoryID_b);
                                      die("Query failed : " . mysql_error());
                                  }
                                  $num++;
                                  break;
                            case "description":
                                $description_b.=$data;
                                  break;
                            default:
                                    break;
                    }
            }

            $xmlParser=xml_parser_create();

            $caseFold=xml_parser_get_option($xmlParser, XML_OPTION_CASE_FOLDING);
            $targetEncoding=xml_parser_get_option($xmlParser, XML_OPTION_TARGET_ENCODING);
                xml_parser_set_option($xmlParser, XML_OPTION_SKIP_WHITE, 1);

            if ($debug>0){
                    echo("Debug is set to: $debug
\n");
                    echo("Case folding is set to: $caseFold
\n");
                    echo("Targer Encoding is set to: $targetEncoding
\n");
            }

            if ($caseFold==1){
                    xml_parser_set_option($xmlParser, XML_OPTION_CASE_FOLDING, false);
            }

            xml_set_element_handler($xmlParser, "startElement", "endElement");
            xml_set_character_data_handler($xmlParser, "characterData");

            if (!($fp = fopen($file, "r"))) {
                  die("could not open XML input: $file");
            }

            while ($data = fgets($fp, 8192)) {         // 4096
                   if (!feof($fp)){
                    if (!xml_parse($xmlParser, $data)){
                            die(sprintf("XML error: %s at line %d", xml_error_string(xml_get_error_code($xmlParser)), xml_get_current_line_number($xmlParser)));
                            xml_parser_free($xmlParser);
                            mysql_close($link);
                    }
                   }else{
                         xml_parser_free($xmlParser);
                         mysql_close($link);
                   }
            }

            xml_parser_free($xmlParser);
            mysql_close($link);

            ?>

Высказать мнение | Ответить | Правка | Наверх | Cообщить модератору

Архив | Удалить

Индекс форумов | Темы | Пред. тема | След. тема
Оцените тред (1=ужас, 5=супер)? [ 1 | 2 | 3 | 4 | 5 ] [Рекомендовать для помещения в FAQ]




Партнёры:
PostgresPro
Inferno Solutions
Hosting by Hoster.ru
Хостинг:

Закладки на сайте
Проследить за страницей
Created 1996-2024 by Maxim Chirkov
Добавить, Поддержать, Вебмастеру