XML を生成するスクリプトを作成しました。非常に基本的な方法を使用して、XML の結果をファイルに保存します。
<?php
// start the output buffer to cache the content
ob_start();
//SOME PHP CODE HERE TO GENERATE CONTENTS ON THE FILE
$cachefile = "results.xml";
// open the cache file for writing
$fp = fopen($cachefile, 'w');
// save the contents of output buffer to the file
fwrite($fp, ob_get_contents());
// close the file
fclose($fp);
// Send the output to the browser
ob_end_flush();
サーバー上のスクリプトを含むファイルの URL に手動で移動すると、スクリプトが実行され、ファイルが作成されます。
ただし、cronジョブとして実行しようとすると、スクリプトが実行され、ファイルに保存されずに出力が生成されます。
理由はありますか?