Results 1 to 8 of 8

Thread: Cron job (php script) not sunning?

  1. #1
    pietje63 is offline x10Hosting Member
    Join Date
    Aug 2009
    Posts
    6

    Cron job (php script) not running?

    I have the following cron jobs configured

    script 1, running each 30 minutes (15 and 45 past hour)

    Minute Hour Day Month Weekday Command
    15,45 * * * * /usr/local/bin/php $HOME/public_html/cronjob.php

    script 2, running once in 2 days



    Minute Hour Day Month Weekday Command
    2 * * /usr/local/bin/php $HOME/public_html/cronjob2.php
    Both scripts run fine from the browser and log to a file. But the cronjobs appear to not be running. Any ideas?
    Last edited by pietje63; 07-31-2012 at 02:13 AM. Reason: Layout and typo

  2. #2
    misson is offline x10 Spammer
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,573

    Re: Cron job (php script) not sunning?

    How are you checking whether or not the cron jobs are running? Are you logging the output of the PHP scripts?
    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Jon Skeet's and Eric Raymond's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

  3. #3
    pietje63 is offline x10Hosting Member
    Join Date
    Aug 2009
    Posts
    6

    Re: Cron job (php script) not sunning?

    Yes, I'm logging (via php fwrite) to a file. When I run the file from the browser I see it is working/logging.

  4. #4
    mraz is offline x10Hosting Member
    Join Date
    Jul 2012
    Posts
    95

    Re: Cron job (php script) not sunning?

    just curious, because time is set as every 15 and 45 of the hour, have you tried to change it to run every min to test it out?

    because needing to wait every 30mins for it run is abit tiring...

  5. #5
    descalzo's Avatar
    descalzo is offline Grim Squeaker
    Join Date
    Jul 2009
    Location
    Ankh-Morpork
    Posts
    8,286

    Re: Cron job (php script) not sunning?

    Quote Originally Posted by mraz View Post
    just curious, because time is set as every 15 and 45 of the hour, have you tried to change it to run every min to test it out?
    Every minute is a violation of the TOS and the cron will be discarded.
    Nothing is always absolutely so.

  6. #6
    mraz is offline x10Hosting Member
    Join Date
    Jul 2012
    Posts
    95

    Re: Cron job (php script) not sunning?

    oops sorry - every 5 mins then

  7. #7
    descalzo's Avatar
    descalzo is offline Grim Squeaker
    Join Date
    Jul 2009
    Location
    Ankh-Morpork
    Posts
    8,286

    Re: Cron job (php script) not sunning?

    Quote Originally Posted by pietje63 View Post
    Yes, I'm logging (via php fwrite) to a file. When I run the file from the browser I see it is working/logging.
    No. If there is an error running your script via cron your logging will not do anything.

    Use a command line like

    Code:
    /usr/bin/php   /home/igor/public_html/cron_job.php >>/home/igor/public_html/cron_log.txt 2>&1
    where "igor" is your cPanel username.

    This will log any "echo" command output along with any failures (file not found, etc).

    Not sure if your second script is set to run when you want.
    Last edited by descalzo; 07-31-2012 at 04:54 AM.
    Nothing is always absolutely so.

  8. #8
    pietje63 is offline x10Hosting Member
    Join Date
    Aug 2009
    Posts
    6

    Re: Cron job (php script) not sunning?

    Quote Originally Posted by mraz View Post
    oops sorry - every 5 mins then
    I choosed for 15,45 to eb able to run both cron jobs together.

    I thought testing by 'browsing' was fine, and than run the script each thirty minutes. I'm not that much in a hurry that I need to run it more often. Would you expect anything else by editing the run frequency?

    Quote Originally Posted by descalzo View Post
    No. If there is an error running your script via cron your logging will not do anything.

    Use a command line like

    Code:
    /usr/bin/php   /home/igor/public_html/cron_job.php >>/home/igor/public_html/cron_log.txt 2>&1
    where "igor" is your cPanel username.

    This will log any "echo" command output along with any failures (file not found, etc).

    Not sure if your second script is set to run when you want.
    Thank you. That is a fair point. Will try tonight.

    Logging added; will report test of log later. Timing was indeed incorrect, now also updated

    It looks like the script is running :-) probably the path to fwrite is different when running cron-php compared to 'normal'.

    Thanks for all input!
    Last edited by pietje63; 07-31-2012 at 01:50 PM.

Similar Threads

  1. Cron Job doesn't run php script (command not found)
    By soulstor in forum Scripts, 3rd Party Apps, and Programming
    Replies: 2
    Last Post: 03-06-2012, 06:30 AM
  2. Cron daily backup script
    By taha116 in forum Scripts, 3rd Party Apps, and Programming
    Replies: 8
    Last Post: 06-30-2009, 05:37 PM
  3. having trouble getting php script to work with cron
    By mikehunt22 in forum Free Hosting
    Replies: 1
    Last Post: 11-02-2008, 09:43 AM
  4. CRON job : script timeout ?
    By webtomata in forum Free Hosting
    Replies: 4
    Last Post: 09-12-2008, 04:23 PM
  5. how to execute php script with cron jobs ?
    By magames in forum Scripts, 3rd Party Apps, and Programming
    Replies: 5
    Last Post: 08-12-2008, 12:15 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
dedicated servers