Hi All I am tryingto run the following script as a Cron job.
I get the following error.
It works if I point my browser at the script.
However if it runs as a cron I get the following error:
<br />
<b>Warning</b>: SimpleXMLElement::__construct() [<a href='simplexmlelement.--construct'>simplexmlelement.--construct</a>]: URL file-access is disabled in the server configuration in <b>/home/spanishp/public_html/currency.php</b> on line <b>9</b><br />
<br />
<b>Warning</b>: SimpleXMLElement::__construct(http://www.ecb.int/stats/eurofxref/eurofxref-daily.xml) [<a href='simplexmlelement.--construct'>simplexmlelement.--construct</a>]: failed to open stream: no suitable wrapper could be found in <b>/home/spanishp/public_html/currency.php</b> on line <b>9</b><br />
<br />
<b>Warning</b>: SimpleXMLElement::__construct() [<a href='simplexmlelement.--construct'>simplexmlelement.--construct</a>]: I/O warning : failed to load external entity "http://www.ecb.int/stats/eurofxref/eurofxref-daily.xml" in <b>/home/spanishp/public_html/currency.php</b> on line <b>9</b><br />
<br />
<b>Fatal error</b>: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in /home/spanishp/public_html/currency.php:9
Stack trace:
#0 /home/spanishp/public_html/currency.php(9): SimpleXMLElement->__construct('http://www.ecb....', 0, true)
#1 {main}
thrown in <b>/home/spanishp/public_html/currency.php</b> on line <b>9</b><br />
<?php
include "connect.inc.php";
$xml = new SimpleXMLElement(
'http://www.ecb.int/stats/eurofxref/eurofxref-daily.xml',
null,
true
);
printf('XML received at %s <br />', $xml->Cube->Cube['time']);
$currency_date = $xml->Cube->Cube['time'];
$rates = array(
'USD' => null,
'DKK' => null,
'GBP' => null,
'SEK' => null,
'NOK' => null,
'RUB' => null,
'AUD' => null
);
foreach($xml->Cube->Cube->Cube as $item){
if(true === array_key_exists((string)$item['currency'], $rates)){
$rates[(string)$item['currency']] = (float)$item['rate'];
}
}
print_r($rates);
echo "<hr>".$rates['GBP']."<br>";
$USD = $rates['USD'];
$DKK = $rates['DKK'];
$GBP = $rates['GBP'];
$SEK = $rates['SEK'];
$NOK = $rates['NOK'];
$AUD = $rates['AUD'];
$RUB = $rates['RUB'];
$query = "INSERT INTO currency
(currency_date,
currency_USD,
currency_DKK,
currency_GBP,
currency_SEK,
currency_NOK,
currency_AUD,
currency_RUB
)values (
'$currency_date',
'$USD',
'$DKK',
'$GBP',
'$SEK',
'$NOK',
'$AUD',
'$RUB'
)";
echo "$query";
$result = mysql_query($query);
?>