Zend Framework and Stock Quotes
by Naneau
While browsing I found this blog post by Greg Neutstaetter. I downloaded his code and tried to get it to work with the current version of the Zend Framework. There were only a few minor modifications that needed to be made for it to work, which tells you something about the stability of the framework. Take a look at the demo to see what it can do.
I have worked in some phpdoc comments, so editors with code assist will display nice hints. Not that you would need much hinting. The class works pretty straightforward. Take a look at greg’s blog for more info, about the symbols you can use for instance.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | Zend_Loader::loadClass('Gregphoto_Service_Yahoo_Stocks'); //load it $stocks = new Gregphoto_Service_Yahoo_Stocks(); //create an instance $stocks->addStocks(array('^DJI', 'NVDA', 'AMD', 'MSFT', 'GOOG')); //add an array of stocks $stocks->setSymbols(array('s','n','l1','c1')); //symbols (information to be retrieved) $stocks->setCacheLimit(60); //it caches internally, this is the number of seconds //before a new request will be made to yahoo $stocks->setCacheDir('somedirectory'); //set a cache directory $info = $stocks->getStockInfo(); //and get the info foreach($info as $stock) { //resultset implements SeekableIterator echo $stock->c1; } |
Download my updated version.
Comments
Hello!
I tried implementing this code on my website, but I get this error message:
Fatal error: Uncaught exception ‘Zend_Cache_Exception’ with message ‘Incorrect option name : automaticserialization’ in /…/Zend/Cache.php:144 Stack trace: #0 /…/Zend/Cache/Core.php(174): Zend_Cache::throwException(‘Incorrect optio…’) #1 /…/Zend/Cache/Core.php(122): Zend_Cache_Core->setOption(‘automaticSerial…’, true) #2 /…/Zend/Cache.php(126): Zend_Cache_Core->__construct(Array) #3 /…/Gregphoto/Service/Yahoo/Stocks.php(264): Zend_Cache::factory(‘Core’, ‘File’, Array, Array) #4 /…/Zend/library/Gregphoto/Service/Yahoo/Stocks.php(195 in /…/Zend/Cache.php on line 144
Also, your example page throws:
Warning: Invalid argument supplied for foreach() in /home/id373/include/library/Zend/Cache/Backend/File.php on line 475
Any ideas how to fix this?
Thank you in advance!
I think this may be a ZF 1.5 related issue. The exception states that your (my) code is trying to use a configuration option that is no longer available, namely “automaticserialization”. You could try to find and remove it?
Thanks for a quick reply. I got it to work after completely removing all the caching functions.
stock quotes…
if you’d like to ask some one else how much they like this post i think the answer is goingto be.. very much, an original blog…