# PHP error only when running from cronjob

**URL:** <https://forum.kirupa.com/t/php-error-only-when-running-from-cronjob/301045>\
**Category:** programming\
**Created:** [December 2, 2009, 8:18pm UTC](https://forum.kirupa.com/t/php-error-only-when-running-from-cronjob/301045 "2009-12-02T20:18:34Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ruiganga](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/ruiganga/32/3679_2.png) [@ruiganga](https://forum.kirupa.com/u/ruiganga)\
**Post date:** [December 2, 2009, 8:18pm UTC](https://forum.kirupa.com/t/php-error-only-when-running-from-cronjob/301045/1 "2009-12-02T20:18:34Z")

</div>

Hi

I have a script, it is very simple:

// call the xml  
$xml = file\_get\_contents(“[http://twitter.com/statuses/user\_timeline/](http://twitter.com/statuses/user_timeline/)” . $myTwitterID . “.xml” );

$directory = “xml”;  
$xmlFileName = “twitts.xml”;  
// cria o XML  
try{  
$fp = fopen($directory.’/’.$xmlFileName, ‘w’);  
fwrite ($fp, stripslashes($xml) );  
fclose($fp);  
echo “\<h1 align = ‘center’\>Script Succeeded - XML file was generated!\<h1\>”;  
echo “\<p align=‘center’\>\<a href=’”.$directory.’/’.$xmlFileName."’\>click to open “.$xmlFileName.”\</a\>\<p /\>";  
} catch (Exception $e) {  
echo “\<h1 align=‘center’\>Script Error - File was \<b\>not\</b\> generated!\</h1\>”;  
}

luckly it works when running mannualy but when it is runned from Cronjob I receive the following message in my email and log:

PHP Warning: fopen(xml/twitts.xml): failed to open stream: No such file or directory in /var/www/vhosts/pathtomyfile/call.php on line 37

PHP Warning: fwrite(): supplied argument is not a valid stream resource in /var/www/vhosts/pathtomyfile/call.php on line 38  
PHP Warning: fclose(): supplied argument is not a valid stream resource in /var/www/vhosts/pathtomyfile/call.php on line 39  
\<h1 align = ‘center’\>Script Succeeded - XML file was generated!\<h1\>\<p align=‘center’\>\<a href=‘xml/twitts.xml’\>click to open twitts.xml\</a\>\<p /\>

Why is this happening only when I run with cronjob?

Thanks for any help
