Jump to content

altering script that uses file_get_contents to use cURL instead


Recommended Posts

hi i have been working with a piece of code i found on a website and edited it to suit a project im working on, it works 95% of the time but on occasion it gives me an error (failed to open stream: HTTP request failed! HTTP/1.0 999 Unknown HTTP Status in) which I googled and based on the results im seeing that I should be using cURL instead however i dont seem to understand how to update the code im currently working with so i thought ill paste what I have here and see if anyone can help me out.


below i have pasted 2 scripts, the first one yahoostock.php which call on the script im having issues with named class.yahoostock.php


$objYahooStock = new YahooStock;
Add format/parameters to be fetched
a – Ask
a2 – Average Daily Volume
a5 – Ask Size
b – Bid
b2 – Ask (Real-time)
b3 – Bid (Real-time)
b4 – Book Value
b6 – Bid Size
c – Change and Percent Change
c1 – Change
c3 – Commission
c6 – Change (Real-time)
c8 – After Hours Change (Real-time)
d – Dividend/Share
d1 – Last Trade Date
d2 – Trade Date
e – Earnings/Share
e1 – Error Indication (returned for symbol changed / invalid)
e7 – EPS Est. Current Year
e8 – EPS Est. Next Year
e9 – EPS Est. Next Quarter
f6 – Float Shares
g – Day’s Low
g1 – Holdings Gain Percent
g3 – Annualized Gain
g4 – Holdings Gain
g5 – Holdings Gain Percent (Real-time)
g6 – Holdings Gain (Real-time)
h – Day’s High
i – More Info
i5 – Order Book (Real-time)
j – 52-week Low
j1 – Market Capitalization
j3 – Market Cap (Real-time)
j5 – Change from 52 Week Low
j6 – Percent Change from 52 Week Low
k – 52-week High
k1 – Last Trade (Real-time) with Time
k2 – Change Percent (Real-time)
k3 – Last Trade Size
k4 – Change from 52 Week High
k5 – Percent Change from 52 Week High
l – Last Trade (with time)
l1 – Last Trade (without time)
l2 – High Limit
l3 – Low Limit
m – Day’s Range
m2 – Day’s Range (Real-time)
m3 – 50 Day Moving Average
m4 – 200 Day Moving Average
m5 – Change from 200 Day Moving Average
m6 – Percent Change from 200 Day Moving Average
m7 – Change from 50 Day Moving Average
m8 – Percent Change from 50 Day Moving Average
n – Name
n4 – Notes
o – Open
p – Previous Close
p1 – Price Paid
p2 – Change in Percent
p5 – Price/Sales
p6 – Price/Book
q – Ex-Dividend Date
r – P/E Ratio
r1 – Dividend Pay Date
r2 – P/E (Real-time)
r5 – PEG Ratio
r6 – Price/EPS Est. Current Year
r7 – Price/EPS Est. Next Year
s – Symbol
s1 – Shares Owned
s7 – Short Ratio
t1 – Last Trade Time
t6 – Trade Links
t7 – Ticker Trend
t8 – 1 Year Target Price
v – Volume
v1 – Holdings Value
v7 – Holdings Value (Real-time)
w – 52 Week Range
w1 – Day’s Value Change
w4 – Day’s Value Change (Real-time)
x – Stock Exchange
y – Dividend Yield
Add company stock code to be fetched from the form in the previous page using $GET method
$stock1= $_GET['stock1'];
$stock2= $_GET['stock2'];
$stock3= $_GET['stock3'];
$stock4= $_GET['stock4'];
$stock5= $_GET['stock5'];
$stock6= $_GET['stock6'];
$stock7= $_GET['stock7'];
$stock8= $_GET['stock8'];
$stock9= $_GET['stock9'];
$stock10= $_GET['stock10'];
$stock11= $_GET['stock11'];
$stock12= $_GET['stock12'];
$stock13= $_GET['stock13'];
$stock14= $_GET['stock14'];
$stock15= $_GET['stock15'];
$stock16= $_GET['stock16'];
$stock17= $_GET['stock17'];
$stock18= $_GET['stock18'];
$stock19= $_GET['stock19'];
$stock20= $_GET['stock20'];
$stock21= $_GET['stock21'];
$stock22= $_GET['stock22'];
$stock23= $_GET['stock23'];
$stock24= $_GET['stock24'];
$stock25= $_GET['stock25'];
$stock26= $_GET['stock26'];
$stock27= $_GET['stock27'];
$stock28= $_GET['stock28'];
$stock29= $_GET['stock29'];
$stock30= $_GET['stock30'];
$stock31= $_GET['stock31'];
$stock32= $_GET['stock32'];
$stock33= $_GET['stock33'];
$stock34= $_GET['stock34'];
$stock35= $_GET['stock35'];
$stock36= $_GET['stock36'];
$stock37= $_GET['stock37'];
$stock38= $_GET['stock38'];
$stock39= $_GET['stock39'];
$stock40= $_GET['stock40'];
$stock41= $_GET['stock41'];
$stock42= $_GET['stock42'];
$stock43= $_GET['stock43'];
$stock44= $_GET['stock44'];
$stock45= $_GET['stock45'];
$stock46= $_GET['stock46'];
$stock47= $_GET['stock47'];
$stock48= $_GET['stock48'];
$stock49= $_GET['stock49'];
$stock50= $_GET['stock50'];
$stock51= $_GET['stock51'];
$stock52= $_GET['stock52'];
$stock53= $_GET['stock53'];
$stock54= $_GET['stock54'];
$stock55= $_GET['stock55'];
$stock56= $_GET['stock56'];
$stock57= $_GET['stock57'];
$stock58= $_GET['stock58'];
$stock59= $_GET['stock59'];
$stock60= $_GET['stock60'];
$stock61= $_GET['stock61'];
$stock62= $_GET['stock62'];
$stock63= $_GET['stock63'];
$stock64= $_GET['stock64'];
$stock65= $_GET['stock65'];
$stock66= $_GET['stock66'];
$stock67= $_GET['stock67'];
$stock68= $_GET['stock68'];
$stock69= $_GET['stock69'];
$stock70= $_GET['stock70'];
$stock71= $_GET['stock71'];
$stock72= $_GET['stock72'];
$stock73= $_GET['stock73'];
$stock74= $_GET['stock74'];
$stock75= $_GET['stock75'];
$stock76= $_GET['stock76'];
$stock77= $_GET['stock77'];
$stock78= $_GET['stock78'];
$stock79= $_GET['stock79'];
$stock80= $_GET['stock80'];
$stock81= $_GET['stock81'];
$stock82= $_GET['stock82'];
$stock83= $_GET['stock83'];
$stock84= $_GET['stock84'];
$stock85= $_GET['stock85'];
$stock86= $_GET['stock86'];
$stock87= $_GET['stock87'];
$stock88= $_GET['stock88'];
$stock89= $_GET['stock89'];
$stock90= $_GET['stock90'];
$stock91= $_GET['stock91'];
$stock92= $_GET['stock92'];
$stock93= $_GET['stock93'];
$stock94= $_GET['stock94'];
$stock95= $_GET['stock95'];
$stock96= $_GET['stock96'];
$stock97= $_GET['stock97'];
$stock98= $_GET['stock98'];
$stock99= $_GET['stock99'];
$stock100= $_GET['stock100'];
* Class to fetch stock data from Yahoo! Finance
class YahooStock {
* Array of stock code
private $stocks = array();
* Parameters string to be fetched
private $format;
* Populate stock array with stock code
* @param string $stock Stock code of company
* @return void
public function addStock($stock)
$this->stocks[] = $stock;
* Populate parameters/format to be fetched
* @param string $param Parameters/Format to be fetched
* @return void
public function addFormat($format)
$this->format = $format;
* Get Stock Data
* @return array
public function getQuotes()
$result = array();
$format = $this->format;
foreach ($this->stocks as $stock)
* fetch data from Yahoo!
* s = stock code
* f = format
* e = filetype
$s = file_get_contents("http://finance.yahoo.com/d/quotes.csv?s=$stock&f=$format&e=.csv");
* convert the comma separated data into array
$data = str_getcsv($s, ",", '"');
* populate result array with stock code as key
$result[$stock] = $data;
return $result;
Edited by KingB00ZeR
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...