Skip to content

Instantly share code, notes, and snippets.

@jdkealy
Forked from anonymous/gist:1377728
Created November 18, 2011 20:58
Show Gist options
  • Save jdkealy/1377739 to your computer and use it in GitHub Desktop.
Save jdkealy/1377739 to your computer and use it in GitHub Desktop.
function getPrices($sample_id)
{
if(empty($this->firstRequestTime))
{
$this->setFirstRequestTime(time());
}
print '::' . $this->firstRequestTime . '::';
$url = "https://www.bullioninternational.net/bacml.pricing/domestic/Default.aspx";
$url_check = array ('content'=>file_get_contents ($url, false, stream_context_create (array ('http'=>array ('method'=>'GET')))), 'headers'=>$http_response_header);
$response_type = $url_check['headers'][0];
$this->setResponse($response_type);
$response_type = 'jarjar';
if($response_type == 'HTTP/1.1 200 OK'){
$html = $url_check['content'];
$timestamp = date_create(NULL);
$dom = str_get_html($html);
$goldChart = $dom->find('#Gold', 0)->find('.chart', 0);
$silverChart = $dom->find('#Silver', 0)->find('.chart', 0);
$goldPrices = $this->parse_prices($goldChart, $sample_id, $timestamp);
$silverPrices = $this->parse_prices($silverChart, $sample_id, $timestamp);
return array_merge($goldPrices, $silverPrices);
}elseif(time() - $this->firstRequestTime < 10){ // Continue to check the url for 30 seconds if it fails.
$this->getPrices($sample_id);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment