maros174 Posted March 2, 2010 Share Posted March 2, 2010 This will kill me, it is taking my whole work day - each day, checking for errors so my visitors don't notice... BACKGROUND: I have a financial website that display's Stock Market Data from my country's stock exchange. Stock Market Data is read from an XML file and written to a database. Data is refreshed every ten minutes (around 40 times per day), for 200+ stocks. PROBLEM: Most of the time everything works fine, but, several times each day, during a refresh, a data for a random stock, usually only one, is read only partialy. (for example. instead of HighPrice=320.99, to a database is written HighPrice=99, or, instead of DailyLow=4270.01, database contains DailyLow=70.01 ) PROBLEM SCRIPTS: XML.class.php - parses XML data and places it in a structured PHP array ZSE.class.php - reads the data and writes it to a database. (I suspect function getMarketTradingData could be an issue (on lines 167-209), everything above just writes to a database) Potentially important facts: XML is allways clean of errors. Time of data collection(refresh) is not important, sometimes the error appears at 10:25, sometimes at 12:35, sometimes at 15:45, etc... Usually the error is limitied to only one stock out of 200+, rarely two or three of them have errors. Data is collected for several fields - but only one has an error: High Price, Low Price, Closing Price, Buy Price, Sell Price, Volume, Average Price. But every time the data is read partially it is limited to only one field. For example, sometimes the Closing price has an error (to a database is written 16 instead of 316), sometimes some other price like daily low price or average price. Dellimiter is not an issue, the data is read partially independent of it. For e.g. sometimes instead of Average Price=24.49 to a database is written only the decimal part 49, sometimes instead of SellPrice=3420 database contains SellPrice=20. Example: [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/193895-parse-xml-write-to-a-database-please-help/ Share on other sites More sharing options...
maros174 Posted March 4, 2010 Author Share Posted March 4, 2010 Anybody? .... I could really use some help on this one. Is it possible that nobody knows what could be wrong here ? Quote Link to comment https://forums.phpfreaks.com/topic/193895-parse-xml-write-to-a-database-please-help/#findComment-1021309 Share on other sites More sharing options...
harristweed Posted March 4, 2010 Share Posted March 4, 2010 I think the problem is this line in XML.class.php while ($file_content = fread($fp, 4096)) { Best option ditch the class and write a custom parser using php5 and simplexml_load_file Else you could try altering the line to while ($file_content = fread($fp, 10000)) { or/and line 69 $reference[$name][$this->_levelsNumbering[$i][$name]] =$reference[$name][$this->_levelsNumbering[$i][$name]]. $data; Quote Link to comment https://forums.phpfreaks.com/topic/193895-parse-xml-write-to-a-database-please-help/#findComment-1021358 Share on other sites More sharing options...
maros174 Posted March 4, 2010 Author Share Posted March 4, 2010 harristweed, thanks for taking the time to look at the code... I'll designate you as my new best friend if we make it work ---- I changed the parameter of fread to 10000 - I am going to keep checking the data every 10 miutes and report here if the errors continue to appear or become rarer. (In any case, the stock market is open for only two more hours, and there may be no more errors today anyway, so I'll have to keep checking tomorrow to see if something pops out...) Just to be sure, could you please check below if I understood right the other modification you suggested. If errors continue to appear I am going to make changes to the line 69 as well. In addition to the above changes, I am going to replace this for ($i = 1; $i <= $this->_currentDepth; $i++) { $name = $this->_xmlpath[$i]; if (!isset($reference[$name])) { $reference[$name] = array(); } if ($i == $this->_currentDepth) { $reference[$name][$this->_levelsNumbering[$i][$name]] = $data; } else { if (!isset($reference[$name][$this->_levelsNumbering[$i][$name]])) { $reference[$name][$this->_levelsNumbering[$i][$name]] = array(); } } $reference = &$reference[$name][$this->_levelsNumbering[$i][$name]]; } with this: for ($i = 1; $i <= $this->_currentDepth; $i++) { $name = $this->_xmlpath[$i]; if (!isset($reference[$name])) { $reference[$name] = array(); } if ($i == $this->_currentDepth) { $reference[$name][$this->_levelsNumbering[$i][$name]] =$reference[$name][$this->_levelsNumbering[$i][$name]]. $data; } else { if (!isset($reference[$name][$this->_levelsNumbering[$i][$name]])) { $reference[$name][$this->_levelsNumbering[$i][$name]] = array(); } } $reference = &$reference[$name][$this->_levelsNumbering[$i][$name]]; } Quote Link to comment https://forums.phpfreaks.com/topic/193895-parse-xml-write-to-a-database-please-help/#findComment-1021392 Share on other sites More sharing options...
maros174 Posted March 4, 2010 Author Share Posted March 4, 2010 Damn. Changing this line in XML.class.php: while ($file_content = fread($fp, 4096)) { to this: while ($file_content = fread($fp, 10000)) { Had no visible effect. There were four errors in less than two hours... same as before... Tomorrow morning I'm going to change line 69 as well. Quote Link to comment https://forums.phpfreaks.com/topic/193895-parse-xml-write-to-a-database-please-help/#findComment-1021446 Share on other sites More sharing options...
harristweed Posted March 4, 2010 Share Posted March 4, 2010 I think this will solve it for you... $reference[$name][$this->_levelsNumbering[$i][$name]] =$reference[$name][$this->_levelsNumbering[$i][$name]].$data notice no space before . and $data I had a similar problem..... Quote Link to comment https://forums.phpfreaks.com/topic/193895-parse-xml-write-to-a-database-please-help/#findComment-1021581 Share on other sites More sharing options...
maros174 Posted March 5, 2010 Author Share Posted March 5, 2010 Three hours... not a single error! I'm afraid to hope... Quote Link to comment https://forums.phpfreaks.com/topic/193895-parse-xml-write-to-a-database-please-help/#findComment-1021902 Share on other sites More sharing options...
maros174 Posted March 5, 2010 Author Share Posted March 5, 2010 First day in a very long time that went without a single error in the data! I still won't celebrate... gonna test it all through monday and report here if it is really working... but it seems to be... :D Quote Link to comment https://forums.phpfreaks.com/topic/193895-parse-xml-write-to-a-database-please-help/#findComment-1022008 Share on other sites More sharing options...
maros174 Posted March 8, 2010 Author Share Posted March 8, 2010 Second day without a single error... I think I can safely say that the script is working flawlessly. harristweed, I can't thank you enough... You really helped me a lot. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/193895-parse-xml-write-to-a-database-please-help/#findComment-1023027 Share on other sites More sharing options...
harristweed Posted March 8, 2010 Share Posted March 8, 2010 you are welcome! Quote Link to comment https://forums.phpfreaks.com/topic/193895-parse-xml-write-to-a-database-please-help/#findComment-1023142 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.