You are not logged in.

#1 2013-12-18 19:10:07

pag-r
Member
From: Poland
Registered: 2011-09-01
Posts: 13

[solved] cron and php problem

I'm wondering why cron works selectivly in my environment

*/1 * * * * php /home/pag-r/public_html/cron.php
*/1 * * * * /usr/bin/echo "something" >> /home/pag-r/public_html/test.txt
//php code from cron.php
<?php

$filename = 'test.txt';
if (file_exists($filename) && is_writable($filename)) {
  file_put_contents($filename, date("Y-m-d H:i:s") . "\n", FILE_APPEND);
} 

And if I cat test.txt, i've got only lines with "something" but none from php script with time. I've tried /usr/bin/php, /usr/bin/php -f, php -f, */1 * *  * * username /usr/bin/php. None of those works. But if I paste all command to terminal, it executes properly. I'm out of ideas where to check. Can't find anything usefull on google so I'm trying here. Any ideas would by much appreciated.

Last edited by pag-r (2013-12-18 20:18:06)

Offline

#2 2013-12-18 19:30:42

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: [solved] cron and php problem

I don't speak php, but

[~] cd /home/karol/public_html/
[public_html]$ php cron.php
PHP Warning:  date(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone. in /home/karol/public_html/cron.php on line 4
[public_html]$ cat test.txt 
something
2013-12-18 19:23:25
[public_html]$ cd
[~]$ php /home/karol/public_html/cron.php
[~]$ cat /home/karol/public_html/test.txt
something
2013-12-18 19:23:25
[~]$ php /home/karol/public_html/cron.php
[~]$ cat /home/karol/public_html/test.txt
something
2013-12-18 19:23:25
[~]$ cd /home/karol/public_html/ && php cron.php
PHP Warning:  date(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone. in /home/karol/public_html/cron.php on line 4
[public_html]$ cat test.txt 
something
2013-12-18 19:23:25
2013-12-18 19:24:43

It seems to work only when I'm in the public_html directory. I ahven't set anything up, I just installed php and created public_html directory, so it may be a false lead.



Edit:

[~]$ touch test.txt
[~]$ php /home/karol/public_html/cron.php
PHP Warning:  date(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone. in /home/karol/public_html/cron.php on line 4
[~]$ cat test.txt 
foo
2013-12-18 19:31:02

Last edited by karol (2013-12-18 19:34:27)

Offline

#3 2013-12-18 20:17:45

pag-r
Member
From: Poland
Registered: 2011-09-01
Posts: 13

Re: [solved] cron and php problem

You've got point. Didn't test it from outside of ~/public_html/ directory. Now when i've changed $filename for full pathname, everything works fine. Thanks for Your help. Problem solved.

Offline

Board footer

Powered by FluxBB