dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 13 of 13

Thread: Automatically sends (server)

  1. #1
    Join Date
    Nov 2004
    Posts
    187

    Angry Automatically sends (server)

    Hi. I have a system where I add emails and birthday dates.

    Today, when it is someoneīs birthday I log in the system and
    manually send all greeting emails.

    I was wondering If somehow my system at the server could
    run by itself and identify that today is day X and that Y users are
    celebrating their birthday so the system should AUTOMATICALLY sends
    all the greeting emails WITHOUT me having to log in and pushing any button.

    Is that possible?? How can I do that?
    Thanks

  2. #2
    Join Date
    Aug 2002
    Posts
    879

    Re: Automatically sends (server)

    If you use a linux server you can use crontab for this
    check-out this tutorial
    http://www.sitepoint.com/article/introducing-cron

  3. #3
    Join Date
    Nov 2004
    Posts
    187

    Re: Automatically sends (server)

    I do use a linux-server but to do that Iīd still need to set a cron MANUALLY at my serverīs cpanel which I canīt.
    How can I do that using a php script to set a cron?

  4. #4
    PeejAvery's Avatar
    PeejAvery is offline Super Moderator Power Poster
    Join Date
    May 2002
    Posts
    10,943

    Re: Automatically sends (server)

    Do you not have access to cpanel? PHP can't set up a cron on a server.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  5. #5
    Join Date
    Nov 2004
    Posts
    187

    Re: Automatically sends (server)

    I do have cpanel but I cant set up a cron manually
    I need somehow to do that using a php script.
    Any other solutions?

  6. #6
    PeejAvery's Avatar
    PeejAvery is offline Super Moderator Power Poster
    Join Date
    May 2002
    Posts
    10,943

    Re: Automatically sends (server)

    I think you misunderstand what a cron is. A cron is simply a scheduled task. Basically, the cron tells the kernel to execute whatever you have set the cron to execute at the time you have set it. PHP is something that can be set by a cron but PHP cannot create a cron.

    Please explain why you can't set the cron manually. You only have to set it once and then the cron executes as you have preset the time.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  7. #7
    Join Date
    Nov 2004
    Posts
    187

    Re: Automatically sends (server)

    I think you didnt understand me.
    I need to run a script automatically but I can never set it to run by myself.
    It needs to run by itself.

    Lets say I need to email you everyday.
    I know I can set a cron to do that.
    What I need is that at the moment you register for example it automatically creates something to send you a message automatically every day.

    How can I do that?

  8. #8
    PeejAvery's Avatar
    PeejAvery is offline Super Moderator Power Poster
    Join Date
    May 2002
    Posts
    10,943

    Re: Automatically sends (server)

    I'm sorry, but I think you are the one mistaken.

    You set a cron. That cron makes the PHP run automatically. You can set the cron once and never have to touch it again. That means it is automatic. How does this not solve your problem?????
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  9. #9
    Join Date
    Nov 2004
    Posts
    187

    Angry Re: Automatically sends (server)

    Quote Originally Posted by PeejAvery
    I'm sorry, but I think you are the one mistaken.

    You set a cron. That cron makes the PHP run automatically. You can set the cron once and never have to touch it again. That means it is automatic. How does this not solve your problem?????

    i CAN NOT set a cron myself.
    It has to be set without me even getting close to that.
    Imagine this:

    You know that
    - clientA needs to send 2 emails every day
    - clientB needs to send 5 emails every weekend
    - clientC needs to send 12 emails every monday

    If I would do what you said I would have to go to my cpanel and set the cron so it would send the emails automatically. I understand that

    The problem is that I dont want to do that
    Iīd like for example that when ClientA, B, C uses my system to choose how many emails he would like to send and when then what I need would be done somehow with a script

    Understand now?

  10. #10
    PeejAvery's Avatar
    PeejAvery is offline Super Moderator Power Poster
    Join Date
    May 2002
    Posts
    10,943

    Re: Automatically sends (server)

    Quote Originally Posted by rogernem
    Understand now?
    Now that you have clearly explained, yes, I do.

    Well, the only way that PHP could set a CRON would be to send it to the kernel. Have you tried any of the following to send a linux command line?

    system
    exec
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  11. #11
    Join Date
    Nov 2004
    Posts
    187

    Re: Automatically sends (server)

    Nope, never have?
    Any idea on how I could do that?

  12. #12
    PeejAvery's Avatar
    PeejAvery is offline Super Moderator Power Poster
    Join Date
    May 2002
    Posts
    10,943

    Re: Automatically sends (server)

    Well, you would have to figure out how to create a cron through the command line within Linux. Those PHP commands send to the command line.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  13. #13
    Join Date
    Jan 2003
    Location
    7,107 Islands
    Posts
    2,487

    Re: Automatically sends (server)

    another way is to create a php shell script with the CLI installed/enable on the PHP configuration. again, the script should be ran only once upon system start up via cron, or let say manually using the command line.

    the main body of the script may be a message loop/pump which may contain one or more procedures that you want to include, one of them of course is your email function. using the IPC mechanism your php web page can send send-email message to the loop.

    Code:
    // perhaps, initialize a semaphore IPC object here
    
    // initialize message queue IPC object here
    
    // perhaps initialize some shared mem IPC object here
    
    
    // set process control handler
    declare(ticks=1);  
    pcntl_signal(SIGTERM, "sig_handler");
    pcntl_signal(SIGINT, "sig_handler");
    .
    .
    etc
    
    // message loop
    do {   
        
      if (msg_receive($msg_id, $i, $msg_type, 16384, $msg, true, MSG_IPC_NOWAIT, $msg_err)) {
    
        switch ($msg['id']) {
           case SEND_EMAIL_MSG:
              my_send_email_function($msg['parameter']);
              break;
        }
    
      }
    
    } while (true);
    
    
    // process control handler
    function sig_handler($signo) {
       switch ($signo) {
          case SIG_TERM:
          case SIG_INT:
             // clean up routine
             break;
          .
          .
          .
          etc
       }
    }

    unfortunately, the Semaphore, Shared Memory and IPC Functions plus the Process Control Function must be enabled/present on your PHP configuration/installation otherwise it will not work. you may check the PHP manual for more info on the funcs/libs.

    just an idea
    Busy

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)