Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Aug 2005
    Posts
    252
    Thanks
    23
    Thanked 0 Times in 0 Posts

    Timeout issues with Mailing List script when sending to a large amount of emails...

    Would you mind looking at these pieces of code and perhaps offer a suggestion or two to work around timeout issues when sending to a large amount of email addresses? The max_execution_time on my server is set to 30 (which I cannot change). This script has a couple built-in featured to supposedly work around these issues but the few tweaks I've made don't seem to help when sending to about a thousand email addresses or more.

    Here's the config section:

    PHP Code:
    // When sending emails, ListMailer will pause periodically to avoid time-outs.  
    // This is helpful is your email list contains a large amount of address.
    // The default value of 100 should suffice under most scenarios.
    $cfg['pauseinterval'] = 100;

    // Number of seconds to pause.
    $cfg['pausetime'] = 3
    and here is the supporting code (hopefully, I've posted enough?):

    PHP Code:
    if (isset($_POST['emailsub'])) {
          
    // fetch addresses and process
          
    $succ 0$fail 0;
          if (
    $cc) {
            
    // send CC email if needed
            
    if (@mail($cfg['ccaddress'], $subj$body$headers)) $succ++;
            else 
    $fail++;
          }
          
    $f openfile($cfg['listfile']);
          if (
    $startnum 0) {
            
    // skip to specified record and start there.
            
    skiptoitem($f$startnum);
          }
          if (
    $startpos 0) {
            
    // startpos is used for resuming. It will override any startnum value.
            
    fseek($f$startpos);
          }
          if (
    $cfg['savemail'] && !$_POST['resume']) {
            
    // save this email only if it's not a resume and it is configured for.
            
    if (($mfile savemail($from$subj$body$startid$ashtml)) === false$err 'Could not save email. Check directory exists and permissions are set correctly.';
          }
          if (!isset(
    $err)) {
            
    // create temp file for resume data
            
    if ($cfg['enableresume'] && $cfg['savemail']) {
              if (
    $_POST['resume']) {
                
    $fr = @fopen($cfg['savemailto'].'/tmp_'.substr($_POST['resume'],4), 'wb');
              }
              else {
                
    $fr = @fopen($cfg['savemailto'].'/tmp_'.$mfile.'.txt''wb');
              }
              if (
    $fr === false$err 'Could not create or open temp file. Check directory permissions.';
            }
            if (!isset(
    $err)) {
              
    // WE'RE READY TO SEND!!!
              
    $cnt 0;
              while (
    $item readitem($f)) {
                
    // pause if we're on a multiple of the pause interval
                
    if ($cfg['pauseinterval'] > && $cnt%(int)$cfg['pauseinterval'] == && $cnt != 0) {
                  
    sleep((int)$cfg['pausetime']);
                }
                
    // fetch addresses and send
                
    if (@mail($item['addr'], $subj$body$headers)) $succ++;
                else 
    $fail++;
                
    $cnt++;
                
    // update the temp file with resume info
                
    if ($cfg['enableresume'] && $cfg['savemail']) {
                  
    rewind($fr);
                  
    fwrite($fr$item['id']."\r\n");
                }
              }
            }
            if (
    $cfg['enableresume'] && $cfg['savemail']) {
              
    // mailing is done, so we delete the temp file
              // or, if this is a resume, delete the old temp file
              
    fclose($fr);
              if (
    $_POST['resume']) {
                
    unlink($cfg['savemailto'].'/'.'tmp_'.substr($_POST['resume'],4));
              }
              else {
                
    unlink($cfg['savemailto'].'/tmp_'.$mfile.'.txt');
              }
            }
          }
        } 
    Thank you in advance!
    Errica

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    The best way to avoid timing out when spamming is to stop spamming.

  • #3
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,853
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    Quote Originally Posted by Fumigator View Post
    The best way to avoid timing out when spamming is to stop spamming.
    That might be a newsletter as well.
    Edit: A forum search in the server-side subforum for the keyword batches would give you some similar threads.
    Last edited by abduraooft; 12-04-2008 at 06:25 PM.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #4
    Regular Coder hinch's Avatar
    Join Date
    Sep 2005
    Location
    UK
    Posts
    923
    Thanks
    25
    Thanked 80 Times in 80 Posts
    this is an issue i'm having atm with one of my sites. luckily its a dedicated server so my quick work around was just simply to increase page time out.

    Alternatively BCC is your friend just stack all the addresses into a BCC field and away you go
    A programmer is just a tool which converts caffeine into code

    My work: http://www.fcsoftware.co.uk && http://www.firstcontactcrm.com
    My hobby: http://www.angel-computers.co.uk
    My life: http://www.furious-angels.com


  •  

    Posting Permissions

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