I’m trying to figure out why cron is giving me false positives as I try to learn cron.
I have a test script that writes the time to a file and echos the time and how many characters were written to the file. Once that works, I plan to use more dynamic data. Note - the file, newtime.txt has permissions 777.
basically the concept is (not actual code):
$test = date(“d/m/y : H:i:s”, time());
$file = fopen(“newtime.txt”,“w”);
$result = fwrite($file,$test);
echo "wrote: “.$result.”, ".$test;
I setup the cron in the DH panel, and it runs and emails me the correct output, which is the number of bytes written and the time that the cron job was run. So the the system finds the php & runs the cron job w/o a problem and has a return value for fwrite > 0, suggesting that the file was written, and the correct text - the time in the email matches the time the cron job was run.
The cron looks like:
BUT, here’s where some guidance would help, the file is not actually written. I can access the file newtime.txt via ftp or ssh, and the file is not updated. WHY would fwrite return a value if the file was not written?
So, from the above it seems that cron has no problem finding and executing the php script as evidenced by the correct output in email and the semblance of the correct number of bytes written by fwrite.
How can I test what’s going on? The result is the same if I place:
above the <?php
You may also wonder if it works if I use a browser. It does - both the screen output is correct, AND the file is correctly updated. Recall that the cron was already doing everything except writing the file earlier. There should be no directory problem.
To make matters more confusing, if I indeed ‘cd’ to the directory of the script, the cron works as it did before, outputing the same value for fwrite, AND also updating the file.
If cron found the script and executed before, why does using ‘cd’ matter? Why is fwrite returning the correct value for bytes written, even when the file was not written? What debugging flags can I use to figure out what’s happening?
Inquiring minds want to know.