SitePoint Sponsor

User Tag List

Page 1 of 2 12 LastLast
Results 1 to 25 of 32
  1. #1
    ********* Articles ArticleBot's Avatar
    Join Date
    Apr 2001
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Discussion thread for Introducing Cron

    This is a dedicated thread for discussing the SitePoint article 'Introducing Cron'

  2. #2
    SitePoint Wizard silver trophy Karl's Avatar
    Join Date
    Jul 1999
    Location
    Derbyshire, UK
    Posts
    4,411
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    IMHO showing PHPs usage as a command line tool would have been far better suited to this article than simply executing a PHP script via the web server using wget. For example what happens to your cron job that must run every 5 minutes when the web server dies - oh dear, no PHP script executed. The article does nothing to further the cause of PHP on the commandline and presents it in a light that would make casual users think PHP can only be executed via a web server.

  3. #3
    Non-Member
    Join Date
    Nov 2002
    Location
    Earth
    Posts
    1,107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Right. It's ridiculous to use wget to call php scripts through apache locally.

    "If you try to run a PHP script in this manner, nothing will happen (barring very special configurations that have PHP compiled as an executable, as opposed to an Apache module). The reason is that, in order for PHP to be parsed, it needs to be passed through Apache. In other words, the page needs to be called via a browser or other means of retrieving Web content."

    Ridiculous. The PHP commandline is often available, and, if not, rather easy to install.

  4. #4
    SitePoint Wizard Crowe's Avatar
    Join Date
    Nov 2001
    Location
    Huntsville
    Posts
    1,117
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    I run all my scripts in cron like this:

    /usr/bin/php /path/to/script.php > null

    This way I avoid using wget or even lynx, both of which count as page views locally, which I don't want.

    Still, for hosts that don't suppor this method the one in this article works great! I've used it in the past and it served me well.
    Chrispian H. Burks
    Nothing To Say

  5. #5
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Umm... I miss read the article title from the side bar actually...

    I thought it was COM, though now that I've read the article I might add that there is nothing new in there from what I've read elsewhere.

    Better luck next time aye ?

  6. #6
    Prolific Blogger silver trophy Technosailor's Avatar
    Join Date
    Jun 2001
    Location
    Before These Crowded Streets
    Posts
    9,446
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks guys. I recognize that there are quite a few ways to do what I demonstrated. More power to you in doing whatever you need to do. Some beginners might want to know, though, eh?

    By the way, csn, in case you didn't know, wget IS a browser...or rather a browser uses port 80 as does wget. PHP is parsed just fine using wget. I agree with Karl though about using PHP from the commandline, but since I have yet to run into many hosting setups that have PHP compiled as a standalone mosdule (as opposed to a PHP module) I chose not to tackle that direction. I did think about it though, and perhaps that's the next article.
    Aaron Brazell
    Technosailor



  7. #7
    SitePoint Wizard
    Join Date
    Mar 2002
    Location
    Bristol, UK
    Posts
    2,240
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I set up my first Cron thingy today

    Every Monday at 1 AM, the MySQL database that my site uses is automatically backed up!

    Thanks for the article, nice and informative

    -Sam
    Sam Hastings

  8. #8
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,235
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Good stuff. I'll have to play with this later today

  9. #9
    Non-Member
    Join Date
    Nov 2002
    Location
    Earth
    Posts
    1,107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Sketch
    By the way, csn, in case you didn't know, wget IS a browser...or rather a browser uses port 80 as does wget. PHP is parsed just fine using wget. I agree with Karl though about using PHP from the commandline, but since I have yet to run into many hosting setups that have PHP compiled as a standalone mosdule (as opposed to a PHP module) I chose not to tackle that direction. I did think about it though, and perhaps that's the next article.
    I definitely _don't_ consider wget to be a browser. It just retrieves files. Programs like lynx, mozilla, ie, opera, etc. are browsers. And using wget should have no effect on how PHP is parsed (and executed) - ANY program should be able to receive the same results by retrieving php scripts on port 80. The main point is that it's rather ridiculous to use wget, thus invoking a web server, to run PHP scripts for server admin tasks when it's possible to call them directly via the command line. It's like saying that you should put all your PERL scripts in a web directory and call them through the web server using wget. Calling such scripts through the web server is completely unnecessary, a waste of resources, and none of the web server functionality is needed (or used).

  10. #10
    Anonymous
    SitePoint Community Guest
    I think you'll find that many Linux distributions include, by default, PHP compiled as an executable as well as an Apache module. In such cases, you can simply run it by: php -f script.php or embed the path to the PHP executable in the top line of the script #!/usr/bin/php. I'm now writing my CRON scripts using PHP, rather than Perl, because it makes it very easy to make a web page out of the PHP script, if I ever need to do that.

  11. #11
    SitePoint Wizard samsm's Avatar
    Join Date
    Nov 2001
    Location
    Atlanta, GA, USA
    Posts
    5,011
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by csn
    The main point is that it's rather ridiculous to use wget, thus invoking a web server, to run PHP scripts for server admin tasks when it's possible to call them directly via the command line.
    Is it usually possible to run php from the command line when you are using the typical $5-$15 a month host? Honest question, I don't know.

    Also, I'm all about the best way to do things, but how much overhead are we talking about here? Most the questions I see on this forum where cron could be useful are things like "How do I switch to a new random image once every 24 hours", that sort of thing. We're talking about one quick script running once every 24 hours.

    I wouldn't have minded more credence to the php executable, but in my opinion, this was more of a tutorial about cron, with PHP included as a familiar point of reference. There actually is a good thread about the PHP executable, it can be found here: SP Forums: Use the Power of the PHP Executable
    Using your unpaid time to add free content to SitePoint Pty Ltd's portfolio?

  12. #12
    Anonymous
    SitePoint Community Guest
    You're the best!
    Just go on with great work!
    man from Republic of Srpska

  13. #13
    TED
    SitePoint Community Guest
    better use wget --spider http://xxx

  14. #14
    SitePoint Enthusiast
    Join Date
    Jan 2004
    Location
    hyderabad
    Posts
    47
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    its great tutorial and have a very practical impact on me.
    I have few issues with it..

    I would like to send 100000 emails through cron job. Is there any problem of script time out problem. If there is a problem..

    phpsharma
    India

  15. #15
    SitePoint Guru worchyld's Avatar
    Join Date
    Jul 2003
    Location
    Newcastle upon Tyne
    Posts
    909
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Send 100 emails every 1 minute or 2 minutes instead of sending them all. You gotta also make sure that the email has not been sent before.

    So, set up a mail_queue table and populate this with every email (including who its going to, the contents, etc) you want to send out.

    Next create a mail-out.php file and limit this to say 100 or 200 and put all your email sending stuff in the mail-out.php file.

    Finally, create a cron file which runs the mail-out.php file every 1 minute. Ensuring that for every email that is sent it updates the mail_queue table setting a flag in the row/table to "sent".

  16. #16
    SitePoint Enthusiast
    Join Date
    May 2003
    Location
    Serbia
    Posts
    53
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is there a good web hosting that offers setting cron jobs? I want some of my scripts to be executed like on every 24 hours... so I'm looking for a good host that offers this. Do most web hostings offer this today or not?

  17. #17
    SitePoint Member
    Join Date
    Mar 2005
    Posts
    0
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here are some useful wget options for calling php scripts in cron:
    -q inhibit wget output, since nobody will be there to see it anyway.
    --tries=1 prevent wget from calling your script more than once if it takes a long time.
    --delete-after prevents wget from creating a separate output file on your server each time the script is called (which it will otherwise do even if the script outputs nothing).
    --http-user, --http-passwd if you want to keep the script in a password protected directory on your server, you can pass the user id and password to wget this way.

    Also, in the php script, it is a good idea to call ignore_user_abort(true); so that wget cannot terminate the script even if it thinks it is taking too long. Call register_shutdown_function to clean up if the script times out (i.e. php timeout).

    P.S. zoki: OneWorldHosting.com will allow cron jobs. You have to apply for SSH access to the server.

  18. #18
    Ken
    SitePoint Community Guest
    Nice tutorial, but the last section is a mystery. What is cronstock?

  19. #19
    SitePoint Member
    Join Date
    May 2006
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Crontab won't work

    Why won't my cron job work?

    test.php:
    Code:
    <?php
    #!/usr/local/bin/php -q
    mail("myemailaddress@gmail.com", "testing", "Hello... this is a cron job");
    ?>
    crontab:
    Code:
    05 * * * * wget http://www.mywebsite.com/test.php

  20. #20
    mahes
    SitePoint Community Guest
    how can i run if am not have permisson to set cron in server

    and
    Why won't my cron job work?

    test.php:
    <?php
    #!/usr/local/bin/php -q
    mail("myemailaddress@gmail.com", "testing", "Hello... this is a cron job");
    ?>

    crontab:

    05 * * * * wget http://www.ang.com/test.php


  21. #21
    chris
    SitePoint Community Guest
    when i use the wget command, the php file is actually just downloaded and saved in the current directory that I am in, and is not parsed by PHP, resulting in nothing happening...

  22. #22
    Ivan
    SitePoint Community Guest
    use "-q" as an extra param to wget so it will not produce any output.
    ex:
    wget -q http://www.example.com/mailstock.php

  23. #23
    Raj Bangar
    SitePoint Community Guest
    wil this work

    05 * * * * php4 /directory_the_php_file_is_in/test.php

    If not how can I run without the broswer, I download and import a very large file, if I do it wit a browser it times out.

  24. #24
    SitePoint Member
    Join Date
    Dec 2006
    Location
    Huddersfield, UK
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by mahes View Post
    how can i run if am not have permisson to set cron in server
    Try phpJobScheduler:
    http://www.dwalker.co.uk/phpjobscheduler/
    it schedules PHP scripts to run at set intervals, your replacement for cron jobs.

    Its free and so long as you have PHP and MySQL it will work fine.

  25. #25
    ash
    SitePoint Community Guest
    use -O /dev/null to suppress writing of a zero length file e.g.
    wget -q http://www.example.com/mailstock.php -O /dev/null


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
  •