-
-
Save jdkealy/1377739 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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