#change for master
YahooStockQuotes
Yahoo Stock Quotes in PHP
What it does
This library makes it simple to access any number of stock prices (and their changes) in your code. It limits itself to one update per day to save your server's (and Yahoo's) resources. It consists of one code file and one cache file. No database necessary.
Merely set the $stockSymbols
array to your list of desired stocks' symbols, include the file, and use the three public functions where you need them.
Simple.
Requirements
There must be a stockQuotes.json
file in the same directory as the stockQuotes.php
file.
stockQuotes.json
must be WRITABLE by the user who owns the PHP process (apache, www-data, nginx, hhvm, etc.).
If the file does not exist or is not writable, every page view will require a new request to Yahoo's servers, which will slow down all page views drastically and get your server blocked by Yahoo.
Example usage
<?php
include 'stockQuotes.php';
?><html>
<head>
<title>Stock Test</title>
</head>
<body>
Price: <?php echo $stockQuotes->getPrice('YHOO'); ?>
<br/>
Change: <?php echo $stockQuotes->getChange('YHOO'); ?>
<br/>
Last updated: <?php echo $stockQuotes->getUpdatedDate(); ?>
</body>
</html>