In my web solution I have a code segment that looks as following, it gets some data and tries to write it to a txt file. This is executed by a cron job.
$filename = "myfile.txt";
if(is_writable($filename)) {
if (!$handle = fopen($filename, 'w')) {
print "Cannot open file ($filename)";
exit;
}
$result_on = mysql_query("SELECT <query>")or die(mysql_error());
$var1 = mysql_num_rows($result_on);
$result_top = mysql_query("SELECT <query>")or die(mysql_error());
$var2 = mysql_result($result_top,0);
$content = $var1 . " " . $var2;
if (fwrite($handle, $content) === FALSE) {
echo "Cannot write to file ($filename)";
exit;
}
fclose($handle);
}
The problem is that the writing process never occurs, even tho no error is generated. What is even more strange is that when I manually browse the file, the writing process occurs as intended.
My crontab looks like this:
* * * * * /usr/bin/php -q /var/www/html/v2/cron.php