#1
  1. .Net Developer
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Location
    London
    Posts
    987
    Rep Power
    15

    Hi,

    How can i do cron job for executing my PHP script once in every day...

    i want to remind the people about their birthday in reminder.php.

    that would be one week before thier birthday and one day before their birthday...

    can i perform this action with cron job??,


    Can you tell me the syntax???.








    ------------------
    shiju
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 1999
    Location
    London UK
    Posts
    7
    Rep Power
    0
    the following is adapted from the script delivered with phpAds <http://www.phpwizard.net>. theoriginal used fetch instead of lynx which i believe is only available on FreeBSD or something...

    59 23 * * * lynx -dump http://ads.ourdomain.net/mail.php3>>/var/log/messages

    an alternative would be to use cgi php (which can be used at the same time as mod_php) in a script with #!/bin/php
    (or whatever your path is) at the top like a perl cgi script
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2000
    Location
    In nederland
    Posts
    41
    Rep Power
    15
    Use this perlscript it runs your php3 code..
    activate the perlscript with cron.

    #!/usr/bin/perl

    my $url = shift;
    $url = URI::URL::url($url, "http://www.??.??/cron.php3")->abs;
    use LWP::UserAgent;
    use HTTP::Request;
    use HTTP::Response;
    use MIME::Base64;
    my $ua = new LWP::UserAgent;
    my $request = new HTTP::Request('GET', $url);
    my $res = $ua->request($request);
    my $result = ($res->is_success)?$res->content:$res->error_as_HTML;
    $result = $1 if $result =~ /<BODY.*?>(.*?)</BODY>/si;
    $result =~ s/(<IMG.*?SRC="?)(.*?)([" >])/$1.URI::URL::url($2, $url)->abs.$3/gies;
    $result =~ s/(<A.*?HREF="?)(.*?)([" >])/$1.URI::URL::url($2, $url)->abs.$3/gies;


    [This message has been edited by jochum (edited June 01, 2000).]
  6. #4
  7. No Profile Picture
    moderator
    Guest
    Devshed Newbie (0 - 499 posts)
    This is how we do it here at ngenuity.
    Simply compile PHP as a CGI binary and move it to somewhere convenient, such as /usr/bin/.

    Then make the first line of the script
    #!/usr/bin/php

    this tells the OS what program to process the script with, exacly like the famous
    #!/usr/bin/perl
    used in perl or the less famous
    #!/bin/sh
    used for most shell scripts.

    Then in the cron tab, you can call the script directly i.e. /data/servers/www.devshed.com/scripts/script.php

    This works great, especially if it is a sensitive script... you can keep it out of your web root and accessable only to your crond.

    Do be sure to keep all the script within <?php ?> tags.

    #!/usr/bin/php
    <?
    ...script here...
    ?>

    Anything print()ed, or echo()ed will be output to stdout, as will anything not in <?php ?>.
  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    2
    Rep Power
    0
    One more question: what if I don't have access to cron on my unix system (I am using a host).
    Is there a way to call lynx from a php page?
    And then not wait for the process to finish?

    Thanks so much
    Sergio
  10. #6
  11. No Profile Picture
    freebsd
    Guest
    Devshed Newbie (0 - 499 posts)
    >>what if I don't have access to cron on my unix system
    Can you run cron locally then? Or another system with cron access remotely to your unix system?

  12. #7
  13. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2000
    Posts
    10
    Rep Power
    0
    >>what if I don't have access to cron on my unix system <<

    You shouldn't have access to run cron. You need to run crontab to configure cron.
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 1999
    Location
    SLC, UT, USA
    Posts
    47
    Rep Power
    15
    Just goes to show you...learn something new everyday.

Similar Threads

  1. Help with cron job!
    By mirthika in forum PHP Development
    Replies: 3
    Last Post: February 7th, 2004, 07:12 PM
  2. PHP cron job editor
    By nybble in forum PHP Development
    Replies: 4
    Last Post: January 27th, 2004, 12:19 PM
  3. cron job for mysql in solaris machine
    By j2me_raj in forum MySQL Help
    Replies: 0
    Last Post: January 21st, 2004, 12:13 AM
  4. cron job problem, pemision denied
    By ovisopa in forum PHP Development
    Replies: 7
    Last Post: January 12th, 2004, 05:29 AM
  5. Cron Job to execute PHP script
    By JoshHarvill in forum PHP Development
    Replies: 16
    Last Post: January 7th, 2004, 10:30 PM

IMN logo majestic logo threadwatch logo seochat tools logo