Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [php/xml] Przszpieszenie kodu aktualizacji xml, Hurtownia azymut
einter-project
post
Post #1





Grupa: Zarejestrowani
Postów: 39
Pomógł: 0
Dołączył: 9.09.2011

Ostrzeżenie: (10%)
X----


Witam

Napisałem integracje z azymut.pl, niestety sama aktualizacja cen trwa kilka godzin. Czy można jeszcze zoptymalizować kod aby aktualizacja trwała krócej?

Tabela z produktami ma 91 026 rekordów i waży 78,6 MB


Plik xml waży 4,9M i ma 76960 linii.

Struktura pliku:

<?xml version="1.0" encoding="ISO-8859-2"?>

<!DOCTYPE prices SYSTEM "http://services.azymut.pl/oferta/price.dtd">
<prices updated="2011-12-16 17:45:38">
<book indeks="00124700100KV" cena="15.41" vat="23" detal="24.61" />
<book indeks="00130100101KA" cena="10.06" vat="23" detal="16.49" />
<book indeks="00151500101KS" cena="8.25" vat="5" detal="11.55" />
<book indeks="00171000105KS" cena="30.8" vat="5" detal="42.0" />
<book indeks="00195900101KS" cena="9.75" vat="5" detal="13.65" />
<book indeks="00204500101KS" cena="15.0" vat="5" detal="21.0" />
<book indeks="00226800101KS" cena="9.75" vat="5" detal="13.65" />

.........


<book indeks="8DB70601415KS" cena="14.93" vat="5" detal="20.9" />
<book indeks="8DB70701415KS" cena="22.43" vat="5" detal="31.4" />
<book indeks="8DB70801415KS" cena="22.43" vat="5" detal="31.4" />
<book indeks="8DB70901415KS" cena="22.43" vat="5" detal="31.4" />
<book indeks="8DB73101415KS" cena="16.43" vat="5" detal="23.0" />
<book indeks="8DB73201415KS" cena="16.43" vat="5" detal="23.0" />
<book indeks="9PA00301415KS" cena="13.61" vat="5" detal="285.8" />
<book indeks="9PA00401415KS" cena="15.0" vat="5" detal="21.0" />
<book indeks="9PB00101415KS" cena="13.5" vat="5" detal="18.9" />
<book indeks="9PB00201415KS" cena="13.5" vat="5" detal="18.9" />
</prices>

Kod php do obsługi pliku:
  1. <?php
  2. $reader = new XMLReader();
  3. $reader->open('ceny4.xml');
  4.  
  5. $counter = 0;
  6. while($reader->read()) {
  7. if($reader->nodeType == XMLReader::ELEMENT && $reader->name == 'book') {
  8. $indeks = $reader->getAttribute('indeks');
  9. $vat = $reader->getAttribute('vat');
  10. $detal = $reader->getAttribute('detal');
  11. $kplD = $reader->getAttribute('kplD');
  12.  
  13.  
  14.  
  15.  
  16. $mysql->exec("UPDATE `shop_product` SET `product_price_update`=now(), `product_price_netto`='".$detal."', `product_komplet`='".$kplD."', `product_vat`='".$vat."'
  17. WHERE `product_number_catalog_producer`='".$indeks."'");
  18.  
  19. print $indeks.' - '.$vat.' - '.$detal.' - '.$kplD.'<br>';
  20.  
  21. $counter++;
  22. }
  23. }
  24. $reader->close();
  25. ?>


Aktualizacja bazy oparta jest o klasę obsługującą PDO

Bardzo prosiłbym o uwagi.

// Edit
Puściłem aktualizacje o 2011-12-16 18:28:15 i do godziny 2011-12-16 19:23:01 zaktualizował 6 448.

Ten post edytował einter-project 16.12.2011, 19:49:28
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
einter-project
post
Post #2





Grupa: Zarejestrowani
Postów: 39
Pomógł: 0
Dołączył: 9.09.2011

Ostrzeżenie: (10%)
X----


Pobawiłem się trochę skryptem i na pewno to wina PDO że tak wolno działa.

Mam teraz do was pytanie które zapytanie będzie bardziej wydajne, najmniej obciąży serwer i które byście zastosowali na takiej dużej bazie:
Opcja 1
  1. <?php
  2.  
  3. $reader = new XMLReader();
  4. $reader->open('ceny4.xml');
  5.  
  6.  
  7.  
  8. $connection = @mysql_connect(DB_SERVER, DB_SERVER_USERNAME, DB_SERVER_PASSWORD)
  9. // w przypadku niepowodznie wyświetlamy komunikat
  10. or die('Brak połączenia z serwerem MySQL.<br />Błąd: '.mysql_error());
  11.  
  12. // nawiązujemy połączenie z bazą danych
  13. $db = @mysql_select_db(DB_DATABASE, $connection)
  14. // w przypadku niepowodzenia wyświetlamy komunikat
  15. or die('Nie mogę połączyć się z bazą danych<br />Błąd: '.mysql_error());
  16.  
  17. $counter = 0;
  18. while($reader->read()) {
  19. if($reader->nodeType == XMLReader::ELEMENT && $reader->name == 'book') {
  20. $indeks = $reader->getAttribute('indeks');
  21. $vat = $reader->getAttribute('vat');
  22. $detal = $reader->getAttribute('detal');
  23. $kplD = $reader->getAttribute('kplD');
  24.  
  25.  
  26. mysql_query("UPDATE `shop_product` SET `product_price_update`=now(), `product_price_netto`='".$detal."', `product_komplet`='".$kplD."', `product_vat`='".$vat."'
  27. WHERE `product_number_catalog_producer`='".$indeks."'");
  28.  
  29. print $counter.' - '.$indeks.' - '.$vat.' - '.$detal.' - '.$kplD.'<br>';
  30.  
  31. $counter++;
  32. }
  33. }
  34. $reader->close();
  35.  
  36. mysql_close($connection);
  37.  
  38. ?>



Opcja 2
  1.  
  2. $reader = new XMLReader();
  3. $reader->open('ceny4.xml');
  4.  
  5. $counter = 0;
  6. while($reader->read()) {
  7. if($reader->nodeType == XMLReader::ELEMENT && $reader->name == 'book') {
  8. $indeks = $reader->getAttribute('indeks');
  9. $vat = $reader->getAttribute('vat');
  10. $detal = $reader->getAttribute('detal');
  11. $kplD = $reader->getAttribute('kplD');
  12.  
  13. $connection = @mysql_connect(DB_SERVER, DB_SERVER_USERNAME, DB_SERVER_PASSWORD)
  14. // w przypadku niepowodznie wyświetlamy komunikat
  15. or die('Brak połączenia z serwerem MySQL.<br />Błąd: '.mysql_error());
  16.  
  17. // nawiązujemy połączenie z bazą danych
  18. $db = @mysql_select_db(DB_DATABASE, $connection)
  19. // w przypadku niepowodzenia wyświetlamy komunikat
  20. or die('Nie mogę połączyć się z bazą danych<br />Błąd: '.mysql_error());
  21.  
  22. mysql_query("UPDATE `shop_product` SET `product_price_update`=now(), `product_price_netto`='".$detal."', `product_komplet`='".$kplD."', `product_vat`='".$vat."'
  23. WHERE `product_number_catalog_producer`='".$indeks."'");
  24.  
  25. mysql_close($connection);
  26.  
  27. print $counter.' - '.$indeks.' - '.$vat.' - '.$detal.' - '.$kplD.'<br>';
  28.  
  29. $counter++;
  30. }
  31. }
  32. $reader->close();
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 27.08.2026 - 20:03