Question

I think I'm confused about exactly what the difference is between running a PHP script as a cron job versus accessing it with a browser. When I test test.php by hitting it with Safari, it writes to a text file as expected, makes DB entries, etc. When it runs as a cron job, it does everything except write to a text file.

I already dealt with it not heading to the PHP parser by inserting: #!/usr/bin/php at the start of the file.

Why won't my script write to my text file via cron, when it works via Safari?

(It's a straight forward fopen, fwrite, fclose bit of code, so revealing it wouldn't be illuminating I don't think)

Was it helpful?

Solution

it will be the user permissions. while the apache (or whatever webserver you are using) may have permission to write to that folder, cron user does not if you make them both members of the same group or make the folder world writable that should solve your problem

keep in mind world writable is not a good security measure

OTHER TIPS

Try to chdir to some existent, writable place before doing the fopen. You never know where the cron runs your stuff.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top