after a week of trying i dont know what else to do.
I have a simple php script that is on my webserver called getpoem.php
The script opens up a website pulls its content and saves it to a poem.txt on the server
//File to extract the Poem of the day
$homepage = file_get_contents('http://SomeWebsite.com/today.php');
$poemALL = substr($homepage,strpos($homepage,"<p>"),strlen($homepage));
. // extracting the poem and saving it to $poemFinish
file_put_contents("poem.txt", $poemFinish); ?>
sudo crontab -u www-data -e
0 3 * * * php /var/www/html/getpoem.php
-rwxrwxrwx 1 www-data www-data 1189 Aug 17 15:07 getpoem.php
-rwxrwxrwx 1 www-data www-data 1335 Aug 17 15:07 poem.txt
2 * * * */usr/bin/php /var/www/html/getpoem.php | > /var/www/html/test.txt
2 * * * */usr/bin/php /var/www/html/getpoem.php | > /tmp/test.txt
When running php from cron, your working directory usually isn't the directory the file is located in. When writing a file, it might try to write the file
poem.txt relative to
/ which usually isn't writable.
So you either set the working directory or you should use "absolute" paths. So for example:
__DIR__ is a magic constant that contains the directory where the current file is in.