EdgarsK Posted May 26, 2010 Report Share Posted May 26, 2010 (edited) Sveiki, parādīšu Jum nelielu koda gabalu kurš sevī ietver masīva izveidi no sql rezultātiem, kur 1 sql satur ~70000, bet 2 sql ~ 40000 Kur ir problēma?! Uzskatu ka kodā nav problēmu izpildīties, vienīgi jautājums par kvalitāti. Tātad viss kods kopējā darbībā neizpildās, bet atsevišķi tas gan izpildās - ko labot lai kods izpildītos kopumā? - a = 1.sql (num_rows=70 000>) - b = 2.sql (num_rows=40 000>) Gadijums 1. foreach(a) { .. } echo 1; # Veiksmīgi foreach(b) { .. } echo 1; # Neveiksmīgi Gadijums 2. foreach(a) { .. } echo 1; # Veiksmīgi (aizkomentēts) foreach(b) { .. } echo 1; # Veiksmīgi Gadijums 3. (aizkomentēts) foreach(a) { .. } echo 1; # Veiksmīgi foreach(b) { .. } echo 1; # Veiksmīgi Kods: <? # sanemam tipu (tips1/tips2) $type = getType(); if($type != 'tips1' && $type != 'tips2') $type=false; $results = array(); # pieprasam tips1 rezultatus if($type==''||$type=='tips1'){ $db1 = Database_::nobuffer_query("SELECT DISTINCT created, count(method) as mcnt FROM tabula WHERE method='tips1' and project_id='{$project}' GROUP BY created ORDER BY id DESC"); if($db1->num_rows()){ foreach($db1->result() as $row){ $date = getTime($row->created,false); if(!isset($results[$date])) $results[$date] = (object)array('tips1'=>$row->mcnt,'tips2'=>0); $results[$date]->tips1 = $results[$date]->tips1 + $row->mcnt; } } } # pieprasam tips1 rezultatus if($type==''||$type=='tips2'){ $db2 = Database_::nobuffer_query("SELECT DISTINCT created, count(method) as mcnt FROM tabula WHERE method='tips2' and project_id='{$project}' GROUP BY created ORDER BY id DESC"); if($db2->num_rows()){ foreach($db2->result() as $row){ $date = getTime($row->created,false); if(!isset($results[$date])) $results[$date] = (object)array('tips1'=>0,'tips2'=>$row->mcnt); $results[$date]->tips2 = $results[$date]->tips2 + $row->mcnt; } } } ?> EDIT: Ja pamaniji kad lietoju DISTINCT un GROUP kopā, tad ignorē to, jo tas ir nepieciešams šajā reizē. Meiģināju atsevišķi arī bez DIST/GRO.. izmaiņas nebija Edited May 26, 2010 by EdgarsA Link to comment Share on other sites More sharing options...
Maris-S Posted May 26, 2010 Report Share Posted May 26, 2010 Ja netiek izdotas nekādas kļūdas, pārliecinies vai skriptam sākumā ir: error_reporting(E_ALL); ini_set('display_errors', 'on'); Skriptā neiedziļinājos, bet ja apstrādā daudz ierakstus, nav gadījumā sasniegts pieļaujamais izpildes laiks? Link to comment Share on other sites More sharing options...
EdgarsK Posted May 26, 2010 Author Report Share Posted May 26, 2010 (edited) tas tak ir pašsaprotami, to es vnk nelieku te piemērā. Ir šīs lietas ieslēgtas. izpildes laiks = +- 1 sekunde Edited May 26, 2010 by EdgarsA Link to comment Share on other sites More sharing options...
rpr Posted May 26, 2010 Report Share Posted May 26, 2010 memory limits? Link to comment Share on other sites More sharing options...
EdgarsK Posted May 26, 2010 Author Report Share Posted May 26, 2010 noop. domaju ka kautkas ar maasivu nav pareizi. luk pameiginaju pamainit sql SELECT FROM_UNIXTIME(created, '%D.%M. %Y.') as created, count(id) as mcnt FROM tabula WHERE method='tips1' and project_id='{$project}' GROUP BY created ORDER BY id DESC domaju varbut php - getTime bremzeja, bet tagad tas pats kas ieprieks Link to comment Share on other sites More sharing options...
Maris-S Posted May 26, 2010 Report Share Posted May 26, 2010 Nav gadījumā ar Database_ objektu kau kas neriktīgi? Pamēģini sataisīt pavisam vienkāršus divus vaicājumus bez cikliem, kas piemēram atgriež kādu vienkāršu rezultātu, vaicājumus sataisi tādā pašā veidā, piemēram: $db1 = Database_::nobuffer_query("select count(id) from tabula"); echo($db1->num_rows()); $db2 = Database_::nobuffer_query("select id from tabula"); echo($db2->num_rows()); Link to comment Share on other sites More sharing options...
cilveks Posted May 26, 2010 Report Share Posted May 26, 2010 Edgar, zinot kā tu programmē. Ieslēdz error reportingus un visus tos @ novāc. Kā arī izej kodam cauri, ņem ārā vietas kur esi atslēdzis erroru reportingu. Es zinu kā tu programmē, visas kļūdas mēdz slēpt/ignorēt, ka tikai lapa kaut kā iet.. Link to comment Share on other sites More sharing options...
EdgarsK Posted May 26, 2010 Author Report Share Posted May 26, 2010 ar database_ objektu viss ir kārtībā. cilveek , cilveki mainas :) arii koda rakstiba mainas. error reportings stav ieslegts, @ zimes manā kodā neeksistē. (izņemot function num_rows(){ if($this->num_rows == 'not-set') $this->num_rows = @mysql_num_rows($this->resource); return $this->num_rows>0?$this->num_rows:0; } Link to comment Share on other sites More sharing options...
EdgarsK Posted May 26, 2010 Author Report Share Posted May 26, 2010 (edited) Nav gadījumā ar Database_ objektu kau kas neriktīgi? Pamēģini sataisīt pavisam vienkāršus divus vaicājumus bez cikliem, kas piemēram atgriež kādu vienkāršu rezultātu, vaicājumus sataisi tādā pašā veidā, piemēram: $db1 = Database_::nobuffer_query("select count(id) from tabula"); echo($db1->num_rows()); $db2 = Database_::nobuffer_query("select id from tabula"); echo($db2->num_rows()); SELECT FROM_UNIXTIME(created, '%D.%M. %Y.') as created, count(method ) AS mcnt FROM tabula WHERE method = 'tips1' AND project_id = '{$project}' GROUP BY created ORDER BY id DESC Num_Rows = 44442 SELECT FROM_UNIXTIME(created, '%D.%M. %Y.') as created, count(id) as mcnt FROM tabula WHERE method='tips2' and project_id='{$project}' GROUP BY created ORDER BY id DESC Num_Rows = 85110 kods nobrūkt tiklīdz sāk izpildīts 2 foreach, bet teiksim ja 1 foreach neizpilda, otrais foreach izpildās Edited May 26, 2010 by EdgarsA Link to comment Share on other sites More sharing options...
Maris-S Posted May 26, 2010 Report Share Posted May 26, 2010 Komentē pa rindiņām ārā un atrodi kuras tieši nenostrādā. Link to comment Share on other sites More sharing options...
EdgarsK Posted May 26, 2010 Author Report Share Posted May 26, 2010 Lūk Database_:: -> $db->result() while($row = mysql_fetch_array($this->resources)){ $return[]=(object)$row; } $this->result = $return; return $return; šajā kodā neredzu īsti problēmu. echo 1; foreach($db2->result() as $row){ echo 2; } echo 3; no si visa tikai 1 paradas Link to comment Share on other sites More sharing options...
briedis Posted May 26, 2010 Report Share Posted May 26, 2010 (edited) var_dump($db2->result()); normāli uzvedas? Edited May 26, 2010 by briedis Link to comment Share on other sites More sharing options...
EdgarsK Posted May 26, 2010 Author Report Share Posted May 26, 2010 hmm, nestrādā vispār. Link to comment Share on other sites More sharing options...
mefisto Posted May 26, 2010 Report Share Posted May 26, 2010 Vai es esmu vienīgais , kuram liekas, ka atgriezt 80000+ rezultātus no DB un tad ar tiem darboties php, velk uz hronisku plānprātību ? Un vai tiešām katrā no tiem 80k+ cikliem , tev vajag izmantot $date = getTime($row->created,false); Un kurā brīdī (object)array('tips1'=>0 ) tiek izmantots ? if($type==''||$type=='tips2'){ // stuff here if(!isset($results[$date])) $results[$date] = (object)array('tips1'=>0,'tips2'=>$row->mcnt); // stuff here } Ehh ... Link to comment Share on other sites More sharing options...
EdgarsK Posted May 26, 2010 Author Report Share Posted May 26, 2010 tu laikam nesekoji līdzi tam ko rakstiju. getTime es nomainīju pret SELECT FROM_UNIXTIME(created, '%D.%M. %Y.') as created, Un kurā brīdī (object)array('tips1'=>0 ) tiek izmantots ? varbūt šeit ? if(!isset) Paraugs -------------------------------------------------------- $date = '12.May. 2010'; if(!isset($results['12.May. 2010'])) $results['12.May. 2010'] = (object)array('tips1'=>0,'tips2'=>$row->mcnt); $date = '13.May. 2010'; if(!isset($results['13.May. 2010'])) $results['13.May. 2010'] = (object)array('tips1'=>0,'tips2'=>$row->mcnt); galā sanāk Results (Array){ 12.May 2010 = (object) tips1 = 512, tips2 = 623 13.May 2010 = (object) tips1 = 5512, tips2 = 6623 14.May 2010 = (object) tips1 = 1512, tips2 = 7623 15.May 2010 = (object) tips1 = 8512, tips2 = 1623 16.May 2010 = (object) tips1 = 6512, tips2 = 7623 } Saproti, sie rezultati ir jaatelo viena lapa, tapec arii tik daudz datu tiek pieprasiti lai varetu sadalit pa dienam, jo dienas veido pec taimstampa. Sakotneji veidojot pielavu so kludu, kad neizveidoju koorinates lai vieglak butu izvilkt realos skaitlus, tagad ir probelemas ar to, tapec lai cinitos talak ludzu jusu palidzibu, nevis izteikumus - kapec tu ta, nevis ta. Link to comment Share on other sites More sharing options...
Recommended Posts