Announcement

Collapse
No announcement yet.

Php Timer Emailing Script Help!!!!

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Mark Hensler
    replied
    Originally posted by aibrahim
    Max,

    How do I run cron from within php do I use a system command like perl?
    Uh, what? Cron has to do with unix, not perl. You don't run cron from within php or perl. Cron is like Window's Scheduled Tasks. You specify a time and a command to execute. When the system time reaches your specified time, cron will run the command you specified.


    Originally posted by aibrahim
    2) The mail function should be after the sleep(30) am I right (every thirty seconds) not before am I right?
    It doesn't matter where the sleep() call is, as long as it is within the loop. It makes no difference whether it sends the email then waits, or waits then sends the email.


    Question:
    Why the heck are you making a script to do this? Use Outlook's Appointments. You can make a recurring appointment, and you'll get this annoying popup to remind you. Complete with a snooze and dismiss button.

    Leave a comment:


  • Conscience
    replied
    HENCE...a cron job is a far easier and better alternative

    Leave a comment:


  • Conscience
    replied
    I am fully aware of this I was replying to a comment made earlier about having a script executing indefinatly.

    In a production environment it is most likely that php scripts are only executable for 30 seconds (its a default) (and thus cannot run indefinatly UNLESS you make a separate ini for that particular script or allow the core ini to process scripts indefinatly)

    If you are just running a test box then thats fine, change the php.ini setting and write a php script that executes indefinatly.

    In a production environment you would have to be crazy to allow this.

    Leave a comment:


  • aibrahim
    replied
    Hi Conciense

    I want the script to execute every 30 seconds not for a duration of 30 seconds. Basically, this is a test case for a script to email me each week telling me to update my web page.

    Leave a comment:


  • Conscience
    replied
    when I say 'can't' i don't mean it in its most literal terms...

    Its not a very good idea at all. It takes up lots resources and you would have to have a separate ini script for it to allow executions over 30secs.

    cron job is definatly the best way to go

    BTW if you are using a php script it should interface with SQL fine..

    Leave a comment:


  • aibrahim
    replied
    Max,

    How do I run cron from within php do I use a system command like perl?

    To jeffct / Max

    #!/usr/bin/php -q
    <?php
    set_time_limit(0);
    PHP Code:
     while(1)
      {
                                              
    sleep(30);
     
    mail (webmaster"Your thirty seconds are up", ..);  
     }
     
    ?> 
    1) Are you telling me this program above will email users every thirty seconds, I do not want it to continuosly mail.

    2) The mail function should be after the sleep(30) am I right (every thirty seconds) not before am I right?

    Leave a comment:


  • Mark Hensler
    replied
    Your also more less likely to have multiple instances of the script running with cron.

    Leave a comment:


  • Mark Hensler
    replied
    You could, but I don't like to have stuff just running forever. Cron is just cleaner, IMO.

    Leave a comment:


  • jeffct
    replied
    Originally posted by Conscience
    you must understand that you can't just leave a php script running
    Well, you can leave one running forever if you want. I would still recommend cron but my point is that I don't see why you "can't just leave a php script running". Fill me in?

    PHP Code:
    #!/usr/bin/php -q
    <?php
    set_time_limit
    (0);

    while(
    1)
    {
         
    // do stuff
        // blah blah

        // wait 30 seconds
        
    sleep(30);
    }
    ?>
    Last edited by jeffct; Thu 28 Mar '02, 12:25pm.

    Leave a comment:


  • kippesp
    replied
    Cron doesn't do anything fancy like interface to MySQL. All it does is fire off a program when told. This should tell you more than enough:

    man crontab
    man cron

    If the above commands don't work, do you have shell access? Are you on Unix/Linux? Man pages can also be read here.

    Use 'crontab -e' to create a cron command.

    This may help as well: http://www.linuxdoc.org/LDP/LG/issue...lman/cron.html

    One question I have: What happens when a cron job is scheduled between 1 am and 2 am on the morning in October when Daylight Savings ends? Does it execute twice? What about between 2 am and 3 am on the morning in April when Daylight Savings begins? Is it skipped that day?
    Last edited by kippesp; Thu 28 Mar '02, 12:01pm.

    Leave a comment:


  • aibrahim
    replied
    COuld anyone guide me to a good user friendly tutorial on cron or at least show me an easy way of doing this.

    ANother quetsion can you use CRON to interface with MYSQL.

    Thanks

    Leave a comment:


  • Conscience
    replied
    max is right....using php for this isn't ideal but if you have to you must understand that you can't just leave a php script running you have to get it to run on timed overvals using either a scheduled event (windows os') or cron jobs (*nix) (well by true deffinition they are both 'cron jobs' but for the sake of this it makes everything a little clearer).

    cron jobs have to be setup though shell usually so if you can't get access to shell or get someone to set it up for you you may have dome diffuculties with this.

    Leave a comment:


  • Mark Hensler
    replied
    If you insist on using PHP, you'll need to setup a cron job to execute it every 30 seconds.

    Leave a comment:


  • aibrahim
    started a topic Php Timer Emailing Script Help!!!!

    Php Timer Emailing Script Help!!!!

    Hi! I am trying to create a script that will email me once a week to remind me to update my webpage or ftp the contents of the webpage for backup. ANyway the functionality is not important
    <b> ALL I NEED IS HOW DO I MAKE A SCRIPT THAT WILL EMAIL ME EVERY 30 SECONDS (AS A TESTCASE) </b>

    HERE IS MY PHP CODE:

    PHP Code:
      <?php
       $year 
    2002;    //start date Mar 27 2002
       
    $month 3;
       
    $day 27;

       
    //echo date("rfc");

       
    $hour 13;  // (based on western (California) timing 1.00 PM 
       
    $minutes 0;
       
    $seconds 0;
       
       
    $email  "[email protected]";  //put your email here

       
    $start_time mktime(($hour+3), $minutes$second$month$day,$year); //3rd november 2001
       //every minute
       
    $time_interval=30;

       
    $offset floor((time() - $start_time));
       print 
    "Count now : $count and offset = $offset\n";
     
      if ((
    $offset%30) == 0//every 30 seconds send an email
       
    {
       
    $count $time_interval;
       print 
    "Inside if count = $count\n";

                       
    $dates date("l d f");         
                   
    $link_tag "http://www.homepage.com/";
                       
    $message "<HTML><BODY>";
                       
    $message .= "<br>";
                       
    $message .= "Please take a chance to view <A HREF=\"http://www.homepage.com\">homepage's</A> weekly feature<br>";
                       
    $message .= "<br><br>";
                       
    $message .= "**** <A HREF=\"http://www.homepage.com\">homepage.com</A> - 
                   where it happens first      ****\n</BODY></HTML>"
    ;
                       
    $headers .= "From: [email][email protected][/email] <[email protected]>\n";
          
                       
    $headers .= "Content-Type: text/html; charset=iso-8859-1\n";
                       
    mail($email"Homepage.com Referal"$message$headers);
                       
    //mail($femail, "Homepage.com Referal" ,$message,$headers);
                       
    echo "Your message has been sent!";

       }
       
    ?>
    Please help me ASAP!! Thanks in advance!
widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
Working...
X