Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

yahoo stock quote 1

Status
Not open for further replies.

jefargrafx

Instructor
Joined
May 24, 2001
Messages
273
Location
US
below is the error I'mgetting when trying to fetch stock quote from yahoo





Warning: fopen() [function.fopen]: php_hostconnect: connect failed in c:\inetpub\ on line 18

Warning: fopen( [function.fopen]: failed to create stream: Bad file descriptor in c:\inetpub\ on line 18

Warning: fgetcsv(): supplied argument is not a valid stream resource in c:\inetpub\ on line 21



here is the code that get is the quote:

// A link to a Yahoo source that provides Stock Quotes and Info in CSV format.
$URL = ("
// Open the URL (to Yahoo to grab the Stock quote Info)
$file = fopen("$URL","r");


is there someting wrong with my $url variable

work great in the browser url address bar?

I checked the php manual with out any luck?

what do yall think?

thanks in advance

jef
 
The PHP online manual section on fopen() states that if the PHP runtime configuration directive allow_url_fopen is set to "off", PHP will emit a warning and the fopen call will fail.

What is your setting for allow_url_fopen?

Want the best answers? Ask the best questions: TANSTAAFL!!
 
You should also look at the CURL functions to contact a remote host and retrieve information.
For stock quotes there may also be web services with SOAP or RSS available.
 
sleipnir214,

thanks for the response, yes, I read that too, however my setting are "on"

both on my test server and dev server, both make the same error.

I am behind a proxy server, could that have something to do with it?

Drj478....thanks for the info...I'll look into it

jef
 
A proxy server could very well be causing the problem, particularly if it's one that uses some kind of vendor-specific integrated authentication to get through the proxy.

Have you tried the URL from the machine that runs your PHP scripts?

Want the best answers? Ask the best questions: TANSTAAFL!!
 
I'll try the url on the server asap

thanks for the advice and I'll let yall know


jef
 
It may very well be the proxy. I have tested the following code on my PHP box:

Code:
<?php
$fh = fopen('[URL unfurl="true"]http://quote.yahoo.com/d?f=snl1d1t1c1p2va2bapomwerr1dyj1&s=bmy',[/URL] 'r');

$foo = fgetcsv($fh, 1024);

print '<pre>';
print_r ($foo);
?>

The output was:

Code:
Array
(
    [0] => BMY
    [1] => BRISTOL MYERS SQ
    [2] => 26.63
    [3] => 9/17/2003
    [4] => 11:17am
    [5] => +0.10
    [6] => +0.38%
    [7] => 947500
    [8] => 5414681
    [9] => N/A
    [10] => N/A
    [11] => 26.53
    [12] => 26.50
    [13] => 26.45 - 26.72
    [14] => 20.74 - 29.21
    [15] => 1.21
    [16] => 21.93
    [17] => Nov  3
    [18] => 1.12
    [19] => 4.22
    [20] => 51.625B
)

Want the best answers? Ask the best questions: TANSTAAFL!!
 
it's the proxy or something

I just copied your code and got

Warning: fopen() [function.fopen]: php_hostconnect: connect failed in c:\inetpub\ on line 2

Warning: fopen( [function.fopen]: failed to create stream: Bad file descriptor in c:\inetpub\ on line 2

Warning: fgetcsv(): supplied argument is not a valid stream resource in c:\inetpub\ on line 4


stay tuned

jef
 
okay guys....it a proxy problem, so with a little more help I think I'll have it.

here's what's coded now, I'm just trying to get the array to return right now

<?php

function pfopen($url) {


$proxy_server = &quot;165.89.84.86&quot;;
$proxy_port = 8080;


if (substr($url, 0,7) <> ' {
return false;
}


$proxycon = fsockopen($proxy_server, $proxy_port, $errno, $errstr);



fputs($proxycon,&quot;GET &quot;.$url.&quot; HTTP/1.0 \r\n\r\n&quot;);

$reading_headers = true;
while (!feof ($proxycon)) {
$curline = fgets($proxycon, 4096);

if ($curline==&quot;\r\n&quot;) {
$reading_headers = false;
}
if (!$reading_headers) {
$filecontent = $curline;
}
}

fclose($proxycon);
return $filecontent;


}

$fh = pfopen(&quot; &quot;r&quot;);

$foo = fgetcsv($fh, 1024);

print '<pre>';
print_r ($foo);
?>

and the error

Warning: fgetcsv(): supplied argument is not a valid stream resource in C:\Inetpub\ on line 41

how could that be? I think I'm getting throguht the proxy...how can I tell?

jef
 
Your function does not return a file handle, but rather the contents of the file. Try the following:
Code:
<?php
function pfopen($url) {
    $proxy_server = &quot;165.89.84.86&quot;;
    $proxy_port = 8080;

    if (substr($url, 0,7) <> '[URL unfurl="true"]http://')[/URL] {
        return false;
    }

    $proxycon = fsockopen($proxy_server, $proxy_port, $errno, $errstr);



    fputs($proxycon,&quot;GET &quot;.$url.&quot; HTTP/1.0 \r\n\r\n&quot;);

    $reading_headers = true;
    while (!feof ($proxycon)) {
        $curline = fgets($proxycon, 4096);

        if ($curline==&quot;\r\n&quot;) {
            break;
        }
    }

    return $proxycon;
}

$fh = pfopen(&quot;[URL unfurl="true"]http://quote.yahoo.com/d?f=snl1d1t1c1p2va2bapomwerr1dyj1&s=bmy&quot;,[/URL] &quot;r&quot;);

$foo = fgetcsv($fh, 1024);

fclose($fh);

print '<pre>';
print_r ($foo);
?>

//Daniel
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top