Cron not working properly

Discussion in 'PHP' started by asgsoft, Oct 27, 2007.

  1. #1
    I am very new to cron jobs and I am puzzled completely.

    I have this cron command:
    set to run every hour of the day.

    I set it to write the output to a text file like this:
    $domains1 = array_map('trim', file('domains.txt'));
    
    if (!in_array($domain, $domains1)){
        file_put_contents('domains.txt', "{$domain}\r\n", FILE_APPEND);
    }
    
    PHP:
    I also set it to send the output by email.

    I get the right output in my email but its not writing to the file.

    So where am I going wrong?

    Do I need to have:
    #!/usr/local/bin/php -q
    PHP:
    if so where?

    Thanks
     
    asgsoft, Oct 27, 2007 IP
  2. anarmyofme

    anarmyofme Well-Known Member

    Messages:
    1,136
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    130
    #2
    Is your cron.php file in your root directory?
     
    anarmyofme, Oct 27, 2007 IP
  3. asgsoft

    asgsoft Well-Known Member

    Messages:
    1,737
    Likes Received:
    34
    Best Answers:
    0
    Trophy Points:
    160
    #3
    do you mean /public_html/? if so then it is.
     
    asgsoft, Oct 27, 2007 IP
  4. tonybogs

    tonybogs Peon

    Messages:
    462
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Check the permissions on your domains.txt file

    If you have created the file as www (or some other user) it could be causing problems as Im guessing this job is running as root.

    For the cron to write to the file you will have to make sure the root user has write permissions.

    Alternatively you could try

    Although this will overwrite the file each time its run

    Hope this helps
     
    tonybogs, Oct 27, 2007 IP
  5. anarmyofme

    anarmyofme Well-Known Member

    Messages:
    1,136
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    130
    #5
    Did you ever get it to work? Are you using cpanel? I might have an easy solution for you.
     
    anarmyofme, Oct 28, 2007 IP
  6. asgsoft

    asgsoft Well-Known Member

    Messages:
    1,737
    Likes Received:
    34
    Best Answers:
    0
    Trophy Points:
    160
    #6

    I CHMOD the file to 777, how do I give root writing permission?
    yes I am using cpanel

    It still doesn't write to file but sends me an email with the right output
     
    asgsoft, Oct 28, 2007 IP
  7. anarmyofme

    anarmyofme Well-Known Member

    Messages:
    1,136
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    130
    #7
    Does your file work if you manually type in
    yourdomain.com/cron.php

    Btw, the 1st 3 links in your sig file are not working (for me)
     
    anarmyofme, Oct 28, 2007 IP
  8. asgsoft

    asgsoft Well-Known Member

    Messages:
    1,737
    Likes Received:
    34
    Best Answers:
    0
    Trophy Points:
    160
    #8
    no it doesn't write to the file when I also do that.

    Thanks regarding my sig, I am going to get it sorted ASAP
     
    asgsoft, Oct 28, 2007 IP