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:
<?php $reader = new XMLReader(); $reader->open('ceny4.xml'); $counter = 0; while($reader->read()) { if($reader->nodeType == XMLReader::ELEMENT && $reader->name == 'book') { $indeks = $reader->getAttribute('indeks'); $vat = $reader->getAttribute('vat'); $detal = $reader->getAttribute('detal'); $kplD = $reader->getAttribute('kplD'); $mysql->exec("UPDATE `shop_product` SET `product_price_update`=now(), `product_price_netto`='".$detal."', `product_komplet`='".$kplD."', `product_vat`='".$vat."' WHERE `product_number_catalog_producer`='".$indeks."'"); $counter++; } } $reader->close(); ?>
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.