SitePoint Sponsor

User Tag List

Results 1 to 13 of 13
  1. #1
    SitePoint Wizard
    Join Date
    May 2012
    Posts
    1,107
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Post Getting started in CRON

    Hi, I just want to ask some help on how to use cron,I am not familiar on this and i want learn on how to use this or apply this in php,can you help me please where should i start...

    Thank you in advance.

  2. #2
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,075
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    Via cron scripts you can fire up any executable script on linux at any time you wish. For example you can send out a newletter every day around midnight, clean out uploaded files every hour, checking for incoming mail every minute, etc, etc.

    To find out more about cron checkout the man page, which explains it all.

    What you need to be aware of when running a php script from cron, is that 1) cron doesn't have the same PATH you do, so mostly just calling php won't work, it needs to be /bin/php or something like that (type which php to find out where php is located on your system). And 2) the current directory when running the the php file doesn't necessarily have to be the directory the php file is in.
    The best solution for both 1 and 2 is to use absolute paths for everything (or use __DIR__ (or dirname(__FILE__) for pre-5.3 php versions))
    Rémon - Hosting Advisor

    SitePoint forums will switch to Discourse soon! Make sure you're ready for it!

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  3. #3
    SitePoint Wizard
    Join Date
    May 2012
    Posts
    1,107
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ScallioXTX View Post
    Via cron scripts you can fire up any executable script on linux at any time you wish. For example you can send out a newletter every day around midnight, clean out uploaded files every hour, checking for incoming mail every minute, etc, etc.

    To find out more about cron checkout the man page, which explains it all.

    What you need to be aware of when running a php script from cron, is that 1) cron doesn't have the same PATH you do, so mostly just calling php won't work, it needs to be /bin/php or something like that (type which php to find out where php is located on your system). And 2) the current directory when running the the php file doesn't necessarily have to be the directory the php file is in.
    The best solution for both 1 and 2 is to use absolute paths for everything (or use __DIR__ (or dirname(__FILE__) for pre-5.3 php versions))

    Hi ScallioXTX,thank you for the reply..Is this compatible in windows 7 ?,...is this also will work if i am in my localhost?

    Thank you in advance.

  4. #4
    SitePoint Wizard
    Join Date
    May 2012
    Posts
    1,107
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Hi ScallioXTX, I could not get in this cron,...their is no steps...

    so for example i have this php file C:\wamp\www\CronTest\crontest.php

    inside of this crontest.php
    Code:
      <?php 
        
              echo "Test cron";
    
      ?>
    what is the next thing to do, do i need to open the command prompt and type those example commands that the link provided ?...I am confuse on this.please help me.

    Thank in you in advance.

  5. #5
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,075
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    Windows doesn't have cron. Windows has the task scheduler. I have no experience with it, so I'm not able to help in that regard. Sorry.
    Rémon - Hosting Advisor

    SitePoint forums will switch to Discourse soon! Make sure you're ready for it!

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  6. #6
    SitePoint Wizard
    Join Date
    May 2012
    Posts
    1,107
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ScallioXTX View Post
    Windows doesn't have cron. Windows has the task scheduler. I have no experience with it, so I'm not able to help in that regard. Sorry.
    Oh,I see..so cron is for the linux only...That's why i could not understand the command...Thank you again.

  7. #7
    SitePoint Addict bronze trophy vectorialpx's Avatar
    Join Date
    Dec 2012
    Location
    Bucharest
    Posts
    247
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)

  8. #8
    SitePoint Wizard
    Join Date
    May 2012
    Posts
    1,107
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    i followed in the stackoverflow but it doesn't work...

  9. #9
    SitePoint Member
    Join Date
    Sep 2007
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by jemz View Post
    Hi ScallioXTX, I could not get in this cron,...their is no steps...

    so for example i have this php file C:\wamp\www\CronTest\crontest.php

    inside of this crontest.php
    Code:
      <?php 
        
              echo "Test cron";
    
      ?>
    what is the next thing to do, do i need to open the command prompt and type those example commands that the link provided ?...I am confuse on this.please help me.

    Thank in you in advance.
    If you want to run this script as a schedule script like say, one or twice in a day, week, month or year, just go to your cpanel control panel and you will see cron schedular which you will use to call up your script.

    Cron is mainly used to automate task.

  10. #10
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,075
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    Quote Originally Posted by prince55l View Post
    If you want to run this script as a schedule script like say, one or twice in a day, week, month or year, just go to your cpanel control panel and you will see cron schedular which you will use to call up your script.

    Cron is mainly used to automate task.
    The OP is running this on their local windows machine, so I'm pretty sure they don't have cPanel on there. Besides, under the hood cPanel is using cron for these kinds of tasks as well, you just don't notice it because you don't interface with it directly.
    Rémon - Hosting Advisor

    SitePoint forums will switch to Discourse soon! Make sure you're ready for it!

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  11. #11
    SitePoint Guru bronze trophy
    Join Date
    Feb 2013
    Posts
    733
    Mentioned
    7 Post(s)
    Tagged
    0 Thread(s)
    You might look into "fakecron". I used it on a windows project and it worked well once path issues were sorted out. Unlike cron where you'd set a time it relies on a page hit to trigger the script.

  12. #12
    SitePoint Wizard
    Join Date
    May 2012
    Posts
    1,107
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Hi, I already tried in the windows task scheduler,Thank you for your help.

  13. #13
    SitePoint Member
    Join Date
    Jun 2013
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    To become more comfortable with the cronjob scheduling aspects of your question, try the interactive cron simulator at http://www.dataphyx.com/cronsandbox/. It gives you the chance to try out different values of the crontab timing parameters to see what run-times you would get.


Bookmarks

Posting Permissions

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