PHP Retrieving Stock Data

jayie1975

New Member
Messages
4
Reaction score
0
Points
0
I have been using the following code to retrieve stock data from Yahoo for over a year now:

$live = "http://download.finance.yahoo.com/d/quotes.csv?s=" . $_GET["code"] . "&f=sb2m3m7et8n4e7e8e9ia2";
$file=fopen($live,"r") or exit("Unable to open file!");
while(!feof($file))
{
echo fgets($file). "<br />";
}
fclose($file);

Just recently it has stopped working. I first noticed it on a WordPress Widget I wrote. The only error it gives me is a timeout error. If I leave it to timeout then it obviously suspends my account (which gets annoying after a while). I've been using this code in many PHP Stock Data projects and they have all stopped working! Strangely if you paste the constructed $live string directly as a URL then it works fine. It just shows the data in the web browser as expected. But not in PHP! I've tried using the PHP "file" command to read the constructed URL into an array but it produces the same error.

I'm I doing something wrong? Help would be appreciated.

If you'd like a $_GET["code"] variable to test then try 'LLOY.L'

Many thanks,

Jason.
 

lemon-tree

x10 Minion
Community Support
Messages
1,420
Reaction score
46
Points
48
This is because port 80 has been blocked to all outgoing connections from the free servers. This was put in place to prevent the use of proxies and I don't think it is going to be reversed any time soon.
If the Yahoo server you are requesting to has the same IP on every request, it is possible that you could have that added to the whitelist for outgoing connections.
 

jayie1975

New Member
Messages
4
Reaction score
0
Points
0
This is because port 80 has been blocked to all outgoing connections from the free servers. This was put in place to prevent the use of proxies and I don't think it is going to be reversed any time soon.
If the Yahoo server you are requesting to has the same IP on every request, it is possible that you could have that added to the whitelist for outgoing connections.

Thankyou lemon-tree. Do you know if that has been implemented recently? Because that would explain why it's only just stopped working.

Although strangely my friend uses Hostgator for his websites and this code also fails.

Jason.
 

lemon-tree

x10 Minion
Community Support
Messages
1,420
Reaction score
46
Points
48
It was put in place relatively recently, within the past month or two. I would assume that other hosting companies may have the same system.
 
Top