Hello, I have a problem when creating file with cron job via cpanel. In the same file there is a query to a database (INSERT), so surely each hour runs cron. But the file ( mycron.txt ) is not created. However, if you access the script through a browser, a file is created Here is part of the script to create a file: $myfile = fopen("/home/mysite/public_html/mycron.txt", 'w'); $txt = "test1\n"; fwrite($myfile, $txt); fclose($myfile); Code (markup): And here is cron Minute Hour Day Month Weekday 0 * * * * /usr/local/bin/php -q /home/mysite/public_html/crontest.php /dev/null 2>&1 Code (markup): I am not aware of commands to cron and suppose somewhere error... Can anyone help? Thank you.
Hi bumbar. I imagine you're going through a permissions issue. I bet the folder is writable for the webserver user but not for the user executing the crontab. Fast solution: set the folder to 777 permissions with chmod (chmod 777 filename on the command line). Secure solution: set 777 permissions only for the text file (chmod 777 mycron.txt) and change the writing mode of the php file pointer to "a+". That way you don't create the txt file everytime the cron script runs but you add the content to the existing txt file. Hope it helps!