Cron

Discussion in 'PHP' started by MrLeN, Aug 19, 2011.

  1. #1
    I just created a cron job in cpanel, but it's not working.

    I just want to get something straight, because maybe I am doing it wrong...

    If I go and create a file which creates a new file, ie:

    
    $myFile = "testFile.txt";
    $fh = fopen($myFile, 'w') or die("can't open file");
    $stringData = "Bobby Bopper\n";
    fwrite($fh, $stringData);
    $stringData = "Tracy Tanner\n";
    fwrite($fh, $stringData);
    fclose($fh);
    
    Code (markup):
    ..and then run it in my browser, it creates a file called testFile.txt.

    *All good so far*

    I thought that all I had to do to add a cron in cpanel was to set the time for the cron (ie: every 5 minutes for testing purposes, but once I have it all running, I'll change it to once every 24 hours)... and then just add the location of the file I want to run.

    ie:

    /home/mysite/public_html/myfile.php

    ...I did all that, but it's not working.

    What's the deal? Am I doing it wrong?

    Am I supposed to enter some sort of command, as per step 4 of these instructions (instead of just the file loction)?

    http://www.siteground.com/tutorials/cpanel/cron_jobs.htm
     
    MrLeN, Aug 19, 2011 IP
  2. MancuZ28

    MancuZ28 Greenhorn

    Messages:
    18
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    21
    #2
    You probably need the php command. Try this:

    php -q /home/serverpath/script/file.php

    If that doesn't work (which it might not if PHP is not installed as CGI), then you should be able to do this instead, which just calls it as if it were through a browser:

    wget -q [FULL URL TO YOUR PHP PAGE]
     
    MancuZ28, Aug 19, 2011 IP
  3. MrLeN

    MrLeN Well-Known Member

    Messages:
    406
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    120
    #3
    That works. Thanks :)

    What does the -q do?
     
    MrLeN, Aug 19, 2011 IP
  4. MancuZ28

    MancuZ28 Greenhorn

    Messages:
    18
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    21
    #4
    -q should just tell it not to create any output (I think the q stands for "quiet")
     
    MancuZ28, Aug 19, 2011 IP
  5. MrLeN

    MrLeN Well-Known Member

    Messages:
    406
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    120
    #5
    What kind of output?
     
    MrLeN, Aug 19, 2011 IP
  6. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #6
    PHP sends output to the screen. In your case there isn't any output, but -q will kill any echo command or print command output.
     
    Rukbat, Aug 22, 2011 IP