The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Cpanel cron job..

Discussion in 'General Discussion' started by VARMA457, Jul 24, 2009.

  1. VARMA457

    VARMA457 Member

    Joined:
    Jul 24, 2009
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    1
    Hi,

    I have a problem with cpanel cron job.

    I working on updating table for every 4 hours in PHP..

    If I run the script manually it is updating every row perfectly... it is taking 10minutes...
    But if I run script as a cron job it is not updating all the rows..

    Like out of 10000 row it is updating only 700 rows..
     
  2. That1Swede

    That1Swede Member

    Joined:
    Jul 23, 2009
    Messages:
    17
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Houston, Texas
    How are you running the PHP script in your cron job and how are you running it when you are doing it manually?
     
  3. LiNUxG0d

    LiNUxG0d Well-Known Member

    Joined:
    Jun 25, 2003
    Messages:
    206
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    Gatineau, Quebec, Canada
    Hi,

    You may want to take a look at PHP's functions for:

    max_execution_time

    If the default max_execution_time is not doing too well, then, increasing it may be beneficial.

    You could add some logging to your script to log start time and end time, and print a message every time something is updated via SQL with a time stamp.

    Sort of like:

    Code:
    print "Script run starts: ". date("Y-m-d H:i:s")."\n";
    print "Updated:  ".$record_id." @ ".date("Y-m-d H:i:s")."\n";
    
    Obviously, instead of printing you would store to a file or DB table. Then you can see what happened.

    Logging is your friend. Use it. :)

    It's not really supported by these forums, since it's a PHP/crond issue, and not so much a cPanel-is-not-working-well issue, but I know my way around PHP so I figure I'll lend you a hand if I can.

    Let me know if you have any follow-ups, I'd love to see what I can do to help.

    Warmest regards,
     
  4. VARMA457

    VARMA457 Member

    Joined:
    Jul 24, 2009
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    1
    You mean How I am running script..

    I am using ssh to connect the server and running like php file.php

    Even in cron job also php -q\home\serverpath\folder\php file.php
     
  5. LiNUxG0d

    LiNUxG0d Well-Known Member

    Joined:
    Jun 25, 2003
    Messages:
    206
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    Gatineau, Quebec, Canada
    Hi,

    I don't believe the problem is with HOW you're running it, because really, you said it's running, just, not fast enough or isn't updating all your records. If it's running, and it dies, it's either being killed or it's being interrupted... both have the same end result.

    Run some logging, it will help you determine what's going on.

    Regards,
     
  6. VARMA457

    VARMA457 Member

    Joined:
    Jul 24, 2009
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    1
    In that case If I run the script manually..It is working.. I dont think any problem with php..

    I will put logs..and I will let you know..
     
  7. LiNUxG0d

    LiNUxG0d Well-Known Member

    Joined:
    Jun 25, 2003
    Messages:
    206
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    Gatineau, Quebec, Canada
    Fantastic!

    Check in to the max_execution_time as well. It may be a question of setting the value to something higher in the script that's running... depending on how long 10,000 records in fact update. ;)

    Regards,
     
  8. That1Swede

    That1Swede Member

    Joined:
    Jul 23, 2009
    Messages:
    17
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Houston, Texas
    Consider modifying your cronjob to write any output from the command that's run to a file by adding
    Code:
    >> log.file
    to the end of the cronjob or email it to yourself by using something like
    Code:
    | mail -s "Subject of mail" email@address.com
    at the end of it. It should be able to provide you with a better idea what the issue is in case the script is terminating or spitting out some other debug info.

    Since you're running the PHP script through shell I don't believe the maximum execution time limit will be in effect (provided your PHP is using the CLI SAPI, typing php -v will tell you whether PHP is CGI or CLI) as the PHP docs state that the CLI SAPI default value for it is set to unlimited because:

    source
     
  9. VARMA457

    VARMA457 Member

    Joined:
    Jul 24, 2009
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    1
    Here you go..I got error
    like
    <br />
    <b>Fatal error</b>: Maximum execution time of 30 seconds exceeded in <b>/home/top/public_html/row.php</b>
    on line <b>31</b><br />
     
    #9 VARMA457, Jul 24, 2009
    Last edited: Jul 24, 2009
  10. VARMA457

    VARMA457 Member

    Joined:
    Jul 24, 2009
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    1
    @LiNUxG0d


    I got this error..

    <br />
    <b>Fatal error</b>: Maximum execution time of 30 seconds exceeded in <b>/home/top/public_html/row.php</b>
    on line <b>31</b><br />


    I think cpanel cron job will done from browser...

    can you help regarding this..
     
  11. Spiral

    Spiral BANNED

    Joined:
    Jun 24, 2005
    Messages:
    2,023
    Likes Received:
    7
    Trophy Points:
    0
    Sounds like you need to increase the time alloted to script exection in your PHP.INI file
     
  12. That1Swede

    That1Swede Member

    Joined:
    Jul 23, 2009
    Messages:
    17
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Houston, Texas

    Okay, so that would indicate that the PHP executable is in fact not the using the CLI SAPI and thus not exempt from the maximum execution time limit.

    If PHP isn't being run in 'safe mode' you should be able to simply edit your PHP file and add the following near the top of the file (before any heavy computing and after the opening PHP tag):

    PHP:
    set_time_limit(0);
    That should effectively disable the maximum execution time limit for your script.
     
Loading...

Share This Page