public static function getTicker() { $stocks = "goog,yhoo,idt,iye,mill,pwer,spy,f,msft,x,sbux,sne,ge,dow,t,ge"; $stocks_db = Prediction::find_last_search_FOR_tickers(); $stocks = $stocks_db ? $stocks_db : $stocks; $grabbed_record = array(); $i = -1; foreach (explode(",", $stocks) as $stock) { $i++; // Where the stock quote info file should be... $local_file = storage_path() . DS . 'cache' . DS . $stock . ".csv"; if (!file_exists($local_file) || filemtime($local_file) <= time() - 60 * 60 * 24) { //<-- Else,If it's out-of-date by 15 mins (900 seconds) or more, update it. upsfile($stock); //<--functiom calls to update remote file to local } // Open the file, load our values into an array... $local_file = fopen($local_file, "r"); $stock_info = fgetcsv($local_file, 1000, ","); $font_color = $stock_info[2] >= 0 ? "color: #009900;" : "color: #ff0000;"; $sign = $stock_info[2] >= 0 ? "↑" : "↓"; $grabbed_record[$i]['symbol'] = $stock_info[0]; $grabbed_record[$i]['font_color'] = $font_color; $grabbed_record[$i]['direction'] = $sign; $grabbed_record[$i]['curr_rate'] = sprintf("%.2f", $stock_info[1]); $grabbed_record[$i]['chng_rate'] = sprintf("%.2f", abs($stock_info[2])); fclose($local_file); //<--closes each opened files } return $grabbed_record; }