Reputation: 314
I'm trying to access the historic data on Yahoo's api (with a PHP/Mysql implementation) using this url as an example:
$url = http://ichart.finance.yahoo.com/table.csv?s=INTC&c=2014&f=2015&a=0&d=0&b=1&e=1&g=d&ignore=.csv
This is the code I used to access it:
$filesize = 2000;
$handle = fopen($url, "r");
$raw_quote_data = fread($handle, $filesize);
echo $raw_quote_data;
fclose($handle);
The echo statement is for error checking, to make sure that I'm getting all the data before I store it in my database. However, the $raw_quote_data being returned only has data for the last 30 days of the time range inputted. Because the date range I inputted was from January 1, 2014 to January 1, 2015, it should return 365 days of data. So what am I doing wrong? Where is the rest of the data going?
The first thing I tried, of course, was changing the filesize, which has zero effect on the output.
Upvotes: 1
Views: 313
Reputation: 111
Use file_get_contents()
instead.
$raw_quote_data = file_get_contents($url);
Upvotes: 1
Reputation: 3457
You are requesting a 15kb file and only reading in 2000 bytes. Also note that when you manually read from the buffer, all the data might not have arrived yet. That is why "it made no difference."
Try this instead:
set_time_limit(0);
$file = @fopen($file_path,"rb");
while(!feof($file))
{
print(@fread($file, 1024*8));
ob_flush();
flush();
}
See this article for more information.
Alternatively file_get_contents
may be a simpler approach.
Upvotes: 0