Jump to content

altering script that uses file_get_contents to use cURL instead


kingb00zer
 Share

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

 

<?php
set_time_limit(360);
include('connection.php');
include_once('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)
j4 – EBITDA
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
*/
$objYahooStock->addFormat("soghca");
/**
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'];
$objYahooStock->addStock("$stock1");
$objYahooStock->addStock("$stock2");
$objYahooStock->addStock("$stock3");
$objYahooStock->addStock("$stock4");
$objYahooStock->addStock("$stock5");
$objYahooStock->addStock("$stock6");
$objYahooStock->addStock("$stock7");
$objYahooStock->addStock("$stock8");
$objYahooStock->addStock("$stock9");
$objYahooStock->addStock("$stock10");
$objYahooStock->addStock("$stock11");
$objYahooStock->addStock("$stock12");
$objYahooStock->addStock("$stock13");
$objYahooStock->addStock("$stock14");
$objYahooStock->addStock("$stock15");
$objYahooStock->addStock("$stock16");
$objYahooStock->addStock("$stock17");
$objYahooStock->addStock("$stock18");
$objYahooStock->addStock("$stock19");
$objYahooStock->addStock("$stock20");
$objYahooStock->addStock("$stock21");
$objYahooStock->addStock("$stock22");
$objYahooStock->addStock("$stock23");
$objYahooStock->addStock("$stock24");
$objYahooStock->addStock("$stock25");
$objYahooStock->addStock("$stock26");
$objYahooStock->addStock("$stock27");
$objYahooStock->addStock("$stock28");
$objYahooStock->addStock("$stock29");
$objYahooStock->addStock("$stock30");
$objYahooStock->addStock("$stock31");
$objYahooStock->addStock("$stock32");
$objYahooStock->addStock("$stock33");
$objYahooStock->addStock("$stock34");
$objYahooStock->addStock("$stock35");
$objYahooStock->addStock("$stock36");
$objYahooStock->addStock("$stock37");
$objYahooStock->addStock("$stock38");
$objYahooStock->addStock("$stock39");
$objYahooStock->addStock("$stock40");
$objYahooStock->addStock("$stock41");
$objYahooStock->addStock("$stock42");
$objYahooStock->addStock("$stock43");
$objYahooStock->addStock("$stock44");
$objYahooStock->addStock("$stock45");
$objYahooStock->addStock("$stock46");
$objYahooStock->addStock("$stock47");
$objYahooStock->addStock("$stock48");
$objYahooStock->addStock("$stock49");
$objYahooStock->addStock("$stock50");
$objYahooStock->addStock("$stock51");
$objYahooStock->addStock("$stock52");
$objYahooStock->addStock("$stock53");
$objYahooStock->addStock("$stock54");
$objYahooStock->addStock("$stock55");
$objYahooStock->addStock("$stock56");
$objYahooStock->addStock("$stock57");
$objYahooStock->addStock("$stock58");
$objYahooStock->addStock("$stock59");
$objYahooStock->addStock("$stock60");
$objYahooStock->addStock("$stock61");
$objYahooStock->addStock("$stock62");
$objYahooStock->addStock("$stock63");
$objYahooStock->addStock("$stock64");
$objYahooStock->addStock("$stock65");
$objYahooStock->addStock("$stock66");
$objYahooStock->addStock("$stock67");
$objYahooStock->addStock("$stock68");
$objYahooStock->addStock("$stock69");
$objYahooStock->addStock("$stock70");
$objYahooStock->addStock("$stock71");
$objYahooStock->addStock("$stock72");
$objYahooStock->addStock("$stock73");
$objYahooStock->addStock("$stock74");
$objYahooStock->addStock("$stock75");
$objYahooStock->addStock("$stock76");
$objYahooStock->addStock("$stock77");
$objYahooStock->addStock("$stock78");
$objYahooStock->addStock("$stock79");
$objYahooStock->addStock("$stock80");
$objYahooStock->addStock("$stock81");
$objYahooStock->addStock("$stock82");
$objYahooStock->addStock("$stock83");
$objYahooStock->addStock("$stock84");
$objYahooStock->addStock("$stock85");
$objYahooStock->addStock("$stock86");
$objYahooStock->addStock("$stock87");
$objYahooStock->addStock("$stock88");
$objYahooStock->addStock("$stock89");
$objYahooStock->addStock("$stock90");
$objYahooStock->addStock("$stock91");
$objYahooStock->addStock("$stock92");
$objYahooStock->addStock("$stock93");
$objYahooStock->addStock("$stock94");
$objYahooStock->addStock("$stock95");
$objYahooStock->addStock("$stock96");
$objYahooStock->addStock("$stock97");
$objYahooStock->addStock("$stock98");
$objYahooStock->addStock("$stock99");
$objYahooStock->addStock("$stock100");
?>
<?php
set_time_limit(360);
/**
* 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
 Share

×
×
  • Create New...