Cron problem Arrgggghhhh!

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( [<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 &quot;; 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 />

include "";

$xml = new SimpleXMLElement(

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'];

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 
)values (

echo "$query";
$result = mysql_query($query);


Some systems have different config files for php, depending on if they’re running from the apache or cgi interface.

Try this from the command prompt to see if you have the right permission:

$ php -i | grep allow_url_fopen

As pmw57 says, it looks as if PHP does not have the right to go and fetch that file - for sensible reasons - you should not trust data from external sources.

There are ways round this, and one of the most popular ways is to use cURL.

IMO, You are making the problem harder to debug for yourself by trying to do 2 things at once.

a) fetch a file
b) extract some terms

So you should be prepared to write the file somewhere when you fetch it.

Task a) has quite a high chance of failing, so you have to be prepared to:

i) try and fetch it again (something cURL does)
ii) report this failure to you, is it a show stopper? Does your biz depend on it?
iii) fall back to using an old file (the previously fetched file)

THEN extract the terms.