SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Hybrid View

  1. #1
    SitePoint Evangelist
    Join Date
    Oct 2000
    Posts
    430
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    sleep() function for delay e-mail

    Hi,

    I've used the sleep function before and its quite useful. However I was thinking that I could possibley use it for the following:-

    I have a formmail script which takes orders on my sites and then e-mails them to me.

    What I would like to do is set up an 'Auto-responder' to mail the customer that their order has been recieved and we are looking into it. However, I think auto responders are rather impersonal and not a great deal of use (due to the fact people easily recognise it as a robot).

    To get round this I want to do two thinks: -

    The first is to put the persons first name in the Dear "Persons Name" part of the e-mail - this I can do.

    However, the next thing I want to do is set it up so the response is sent approaximately 15 minutes after the order is processed - this will make it look like 'someone' has recieved the mail looked at it and sent a prompt reply (instant=robot 15mins=prompt reply) - thants my thinking.

    So the only simple way I can think of doing this is to get the script to sleep() for 15mins then continue.

    Can you do this ? My thinking is that the script may terminate if the user moves off the page.

    Any thoughts ??

    Thanks

    PS I may even take it a step further by making a rand() number of minutes before reply - but always prompt - HeHe
    Last edited by ChilliBoy; Sep 6, 2001 at 07:43.

  2. #2
    code addict Abstraction's Avatar
    Join Date
    Apr 2001
    Location
    Des Moines, IA
    Posts
    346
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The user would have to stay on the page for 15 minutes for the email to get sent unless the script time outs before that. Regardless of the wait, a automatic response is still recognizable.

  3. #3
    SitePoint Evangelist
    Join Date
    Oct 2000
    Posts
    430
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is there any way this could possibly be done ?

    Regardless of the wait, a automatic response is still recognizable.
    I think that depends on how well the e-mail is personalised towards what the customer entered on the form.

  4. #4
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You don't want to put your php script to sleep for 15 minutes! I am sure that there are probably lots of things that will time out - including Apache. It will no doubt kill the script (I'm guessing here - but its a pretty educated guess that there is some safety feature built into Apache that will cause it to kill the script after a time out).

    There will be some solution - but it have to occur outside the web server. Here is a thought - you save the details needed to send the email somewhere - a flat file of databse entry (user email address, first name, last name, whatever else). You write a script that will grab these saved details for "pending" email autoresponses, send the emails and delete the data or mark the record/file as processed. You set up a cron to run the script every 15 minutes or so. The script will only process those files/records that are older than 15 minutes. I must admit that I actually use PHP outside the web server for this type of job because it is currently the scripting langauge I am most productive in. I just have to use the majic path directive to my php binary at the begining of the script as you would do with a perl script:

    #!/usr/local/bin/php
    <?php

    And there is a flag you use when you call the script from the command line that suppresses the output (which otherwise is directed to stdout) - forgot what it is at the mo :P

  5. #5
    SitePoint Evangelist
    Join Date
    Oct 2000
    Posts
    430
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Cheers Sid,

    I thought Cron may be the only option if the sleep() was not possible or a bad idea. I was sort of thinking along the lines you suggested as a possible alternative - however it could be a lot of work just to get a 15 min delay.

    Guess I'll just have to weigh it up and consider if it is worth the effort.

    Thanks for the advice.


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
  •