SitePoint Sponsor

User Tag List

Results 1 to 17 of 17
  1. #1
    You want what? By when?? Milamber's Avatar
    Join Date
    Jan 2001
    Location
    California
    Posts
    342
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here's the problem (as I have learned it from my research)..

    With a list of about 100 people, i go in and I hit send message to list.

    The query gets done. The script starts looping and sending out emails. No biggie so far.

    However, this takes a while and then the browser times-out the operation and it stops half-way through. Bummer!


    How do I get around this issue? I have seen the idea of making a bunch of bcc's, but that's not going to work because my emails are customer specific.

    I've also heard of running the script from the shell so there is no timeout. Well, this has to be web based in operation. So if there's some way that PHP can run the script through the shell, peachy. I've also heard rumors of CGI's being able to run that sort of thing.

    What are some of my options here?

    Thanks...
    -Jeff Minard | jrm.cc - Battlefield 2 Stats

  2. #2
    <? echo "Kick me"; ?> petesmc's Avatar
    Join Date
    Nov 2000
    Location
    Hong Kong
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    What script is this that is doing this? I've heard that PHP scripts are less likely to timeout?

    How long is it taking to sned these 100 emails? It should theoretically take about 2 seconds or so, maybe less, maybe more.

    I'm sure you can run PHP from shell try:

    php file.php

    ALthough that most likely won't work, but that depends on the script that you are using. If the message, from, and subject where hard coded or from the database then it may work but otherwise it wouldn't.

  3. #3
    You want what? By when?? Milamber's Avatar
    Join Date
    Jan 2001
    Location
    California
    Posts
    342
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    the set up

    The way it's currently set up is this (short...)


    all scripts are in PHP.

    User goes to a form. enters these:
    -from address
    -subject
    -body

    form elements are passed to a php script.

    script goes to db and extracts emails + other info.

    Then script does a while loop using this:

    PHP Code:
    while ($row mysql_fetch_array($result)) { 
    also included in the while loop is this. If in the body text the script finds this "!fName" it replaces that with the firstname from the database row currently selected. (there are 7 different things that get replaced each time.)

    Then the script displays a page that says all the emails that were emailed and "Done".

    However, when sending to a list of about 100 people, the browser just stops! (IE 5.01)
    -Jeff Minard | jrm.cc - Battlefield 2 Stats

  4. #4
    Gong!
    Join Date
    May 2000
    Location
    Helsinki, Finland
    Posts
    229
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    One solution you could use is to use something what I call "batch processing" (one of the features I'm thinking to implement to my private newsletter script).

    You basically set a size of the batch (the number of emails that can be sent without browser timeouts) and the scripts then processes the whole list of emails you want to sent in smaller blocks.

    Like if you would have 1000 subscribers and you can send 100 mails without browser timeouts, you would send those emails in 100 blocks. After sending one block, the script could generate a page with meta refresh in it to automatically call the script again to send another block of email.

    Just for example.
    HighCheats - game cheats, codes, tips and tricks for PC and various console platforms

  5. #5
    <? echo "Kick me"; ?> petesmc's Avatar
    Join Date
    Nov 2000
    Location
    Hong Kong
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Why don't you do something like this: (also upgrade browser - may help)

    PHP Code:
    //At the start of the script:

    function getmicrotime(){ 
        list(
    $usec$sec) = explode(" ",microtime()); 
        return ((float)
    $usec + (float)$sec); 
        } 

    $time_start getmicrotime();
        

    // Do other stuff here
    // ANd More

    //Stop the timing and print it:
    $time_end getmicrotime();
    $time $time_end $time_start;

    echo 
    "$time seconds"
    Do this and tell me how long it takes to execute.

    -Peter

  6. #6
    You want what? By when?? Milamber's Avatar
    Join Date
    Jan 2001
    Location
    California
    Posts
    342
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    time's up!

    to email 4 people it took this long...


    Start: 988228551.8491 seconds
    End: 988228554.90474 seconds
    Total: 3.0556490421295 seconds

    hrmm....
    -Jeff Minard | jrm.cc - Battlefield 2 Stats

  7. #7
    You want what? By when?? Milamber's Avatar
    Join Date
    Jan 2001
    Location
    California
    Posts
    342
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    woah!

    to email 10 people this is what it took...


    Start: 988228692.45193 seconds
    End: 988228704.77162 seconds
    Total: 12.319690942764 seconds

    here's the exact code being used in the loop...

    PHP Code:
    while ($row mysql_fetch_array($result)) {
          
    $dts date("F j, Y - g:i a");
          
    $newMail $mailBody;
        
    $newMail str_replace('!email',$row["email"],$newMail);
        
    $newMail str_replace('!fName',$row["fName"],$newMail);
        
    $newMail str_replace('!lName',$row["lName"],$newMail);
        
    $newMail str_replace('!city'$row["city"],$newMail);
        
    $newMail str_replace('!state',$row["state"],$newMail);
        
    $newMail str_replace('!dts',$dts,$newMail);

        if(
    $mailYES=="yes"){
        
    $mailtail str_replace("!link","http://www.freejokebooks.com/remove.php3?email=$row[email]&listName=$listName",$mailtail);
        
    $newMail .= "\r\n\r\n" $mailtail;
        }
        
        
    mail("$row[email]""$subject"$newMail"From: $fromAddress"); 

    -Jeff Minard | jrm.cc - Battlefield 2 Stats

  8. #8
    <? echo "Kick me"; ?> petesmc's Avatar
    Join Date
    Nov 2000
    Location
    Hong Kong
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:

    while ($row mysql_fetch_array($result)) {
          
    $dts date("F j, Y - g:i a");
          
    $newMail $mailBody;
        
    $newMail str_replace('!email',$row["email"],$newMail);
        
    $newMail str_replace('!fName',$row["fName"],$newMail);
        
    $newMail str_replace('!lName',$row["lName"],$newMail);
        
    $newMail str_replace('!city'$row["city"],$newMail);
        
    $newMail str_replace('!state',$row["state"],$newMail);
        
    $newMail str_replace('!dts',$dts,$newMail);

        if(
    $mailYES=="yes"){
        
    $mailtail str_replace("!link","http://www.freejokebooks.com/remove.php3?email=$row[email]&listName=$listName",$mailtail);
        
    $newMail .= "\r\n\r\n" $mailtail;
        }
        
        
    mail("$row[email]""$subject"$newMail"From: $fromAddress"); 

    Firslty I'd say to get rid of anything that doesn't have to be in the loop.

    1. Get the date out of the loop, put it before the while.

    2. Where is $mailYES specified?

    3. I think that the str_replaces are taking up a lot of time thats why I tried to remove them from my script. try to remove any unneccessary one.

    -Peter

  9. #9
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Or create a .htaccess file in the directory where the script lives and put the following line in it:

    php_value max_execution_time 180


    Where 180 is the number of seconds before your script will time out.

    That way for scripts which live in that particular folder they will have 3 minutes to complete the script before the script times out, you can set it to whatever you like.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  10. #10
    You want what? By when?? Milamber's Avatar
    Join Date
    Jan 2001
    Location
    California
    Posts
    342
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by freddydoesphp
    Or create a .htaccess file in the directory where the script lives and put the following line in it:

    php_value max_execution_time 180


    Where 180 is the number of seconds before your script will time out.

    That way for scripts which live in that particular folder they will have 3 minutes to complete the script before the script times out, you can set it to whatever you like.
    Peachy, but what happens if the browser stops? If the person hits "Stop" or closes it, or goes somewhere else or ANYTHING what happens? Will that script continue to run?

    Still ,
    -Jeff Minard | jrm.cc - Battlefield 2 Stats

  11. #11
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I will assume since this script emails out an email to 1000 people that you would be the only one who has access to the script that mails the emails out. If the browser is stopped then the script will end, because the request is cancelled. And since again I assume that you will be the one accessing this script, so what if you get up and leave, if the script hasn't finished before the max_execution_time it will time out, if it finishes before that time then it finishes, I am not sure what your concern is exactly.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  12. #12
    You want what? By when?? Milamber's Avatar
    Join Date
    Jan 2001
    Location
    California
    Posts
    342
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    my concern is that the browser will timeout the operation without me asking it to.
    -Jeff Minard | jrm.cc - Battlefield 2 Stats

  13. #13
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The script is what is timing out, not the browser. I think you are mixing up the way it works. When you initiate your script in the browser it sends a request to the server, if the server times out, it will show you in the broswer that it timed out, but the browser isn't timing out.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  14. #14
    You want what? By when?? Milamber's Avatar
    Join Date
    Jan 2001
    Location
    California
    Posts
    342
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    ereg

    any idea what's up with this not replacing the text it's supposed to?
    PHP Code:
    ereg_replace('!email' "$emil"       $newMail);
    ereg_replace('!fName' "$row[fName]$newMail);
    ereg_replace('!lName' "$row[lName]$newMail); 
    -Jeff Minard | jrm.cc - Battlefield 2 Stats

  15. #15
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Because you need to assign the result of the ereg_replace to a vraibale, you are just running the erge_replace and it does nothing unless you assign the result to a var, try this:

    PHP Code:
    $newMail ereg_replace('!email' $email$newMail);
    $newMail ereg_replace('!fName' $row[fName], $newMail);
    $newMail ereg_replace('!lName' $row[lName], $newMail); 
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  16. #16
    You want what? By when?? Milamber's Avatar
    Join Date
    Jan 2001
    Location
    California
    Posts
    342
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What is faster,

    ereg_replace

    or

    str_replace

    Advantages, disadvantages?
    -Jeff Minard | jrm.cc - Battlefield 2 Stats

  17. #17
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    str_replace is much faster than ereg_replace, ereg_replace is only needed when you need to the added functionality of regular expressions. str_replace() is best when all you are replacing is startight text and there are no wildcards.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.


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
  •