Results 1 to 8 of 8

Thread: PHP performance

  1. #1
    Join Date
    Sep 2009
    Location
    Ontario
    Posts
    1,057
    Provided Answers: 1

    Unanswered: PHP performance

    Code:
    # timex php emailstub.php arlene@xxxx.com jack@xxxx.com "subject data" memo $pdf
                                                                                   
    real       11.24                                                               
    user        0.09                                                               
    sys         0.06
    Code:
         1  <?php                                                                   
         2  $FROM=$argv[1];                                                         
         3  $TO=$argv[2];                                                           
         4  $SUBJECT=$argv[3];                                                      
         5  $MEMO=$argv[4];                                                         
         6  $ATTACH=$argv[5];                                                       
         7  require_once '/u/www/swiftmailer/lib/swift_required.php';               
         8  $letter=`cat $MEMO`;                                                    
         9  $message = Swift_Message::newInstance()                                 
        10          ->setSubject($SUBJECT)                                          
        11          ->setFrom(array($FROM ))                                        
        12          ->setTo(array($TO))                                             
        13          ->setBody($letter)                                              
        14          ->addPart($letter, 'text/html')                                 
        15          ->attach(Swift_Attachment::fromPath($ATTACH))                   
        16  ;                                                                       
        17  $transport=Swift_SmtpTransport::newInstance('smtp.mandrillapp.com',587) 
        18          ->setUsername('jack@xxxx.com')                                  
        19          ->setPassword('my password')                         
        20  ;                                                                       
        21  $mailer=Swift_Mailer::newInstance($transport);                          
        22  $result = $mailer->send($message);                                      
        23  ?>
    What causes the wall clock time to be so great?
    Also is there a better way to write line 8?
    'memo' is a text file with no more than 15 lines of 70 characters each.

  2. #2
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Is the delay some sort of wait response from line 17-20?
    George
    Home | Blog

  3. #3
    Join Date
    Sep 2009
    Location
    Ontario
    Posts
    1,057
    Provided Answers: 1
    I think so, George. When I ran this from home, the task consistently took 10-12 seconds. After I installed it on my client's machine, it took 4 seconds once, and timed out with unable to connect error messages at 30 seconds later. Switching to port 25 (from 587) didn't make any difference.
    Not much help on their web site either http://www.mandrill.com

  4. #4
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    I am not going to pretend to know a lot about what you're doing, but here's some ideas (that you've probably tried already!):

    Because you're experiencing quite different results from two different locations this suggests to me something networky.

    ISP?
    Quote Originally Posted by http://help.mandrill.com/entries/21738477-What-SMTP-ports-can-I-use-
    ISPs may redirect traffic on certain ports, so it's up to you which port you use. It's just a matter of what you prefer and what works for you.
    Quote Originally Posted by http://help.mandrill.com/entries/24633717-Why-am-I-getting-a-Relay-Access-Denied-error-trying-to-send-through-SMTP-
    Ensure that your hosting provider or internet provider (ISP) allows outbound SMTP connections. Some shared hosting providers only allow outbound SMTP connections on dedicated servers, while others block them completely. In some cases, hosting providers might redirect the connection so instead of connecting to smtp.mandrillapp.com, you connect to their local server instead.
    DNS?
    http://www.kitterman.com/spf/validate.html

    Slight tweak to PHP code? Probably makes no difference, but worth a try?
    PHP Code:
    $transport=Swift_SmtpTransport::newInstance('smtp.mandrillapp.com',587
    $transport->setUsername('jack@xxxx.com')                                  
    $transport->setPassword('my password'

    EDIT: Can you try...catch to see if there's an error to help narrow down the problem from the client site? Example here: https://mandrillapp.com/api/docs/exports.php.html
    Last edited by gvee; 02-16-15 at 11:23.
    George
    Home | Blog

  5. #5
    Join Date
    Sep 2009
    Location
    Ontario
    Posts
    1,057
    Provided Answers: 1
    My client was sending out about 500 pay cheque notification emails every two weeks. Their ISP's ISP decided that the emails were spam, and suggested using mandrill.
    My first (foolish) thought was to modify sendmail to use mandrill as the smart host.
    Payday is Wednesday.

  6. #6
    Join Date
    Sep 2009
    Location
    Ontario
    Posts
    1,057
    Provided Answers: 1
    Finally,
    This takes about 2-5 seconds to connect, then processes an email every 4 seconds.
    The batch file contains a space separated list of email addresses and pdf attachment file name.

    Code:
    <?php                                                                   
    $FROM=$argv[1];                                                         
    $SUBJECT=$argv[2];                                                      
    $MEMO=$argv[3];                                                         
    require_once '/u/www/swiftmailer/lib/swift_required.php';               
    $transport=Swift_SmtpTransport::newInstance('smtp.mandrillapp.com',587) 
            ->setUsername('jack@xxxx.com')                                  
            ->setPassword('my password')                         
    ;                                                                       
    $letter=`cat $MEMO`;                                                    
    $handle = @fopen("batch.txt", "r");                                     
    if ($handle) {                                                          
        while (($buffer = fgets($handle, 4096)) !== false) {                
            $p=strpos($buffer," ");                                         
            $TO=substr($buffer,0,$p);                                       
            $ATTACH=rtrim(substr($buffer,$p+1));                            
            echo $TO."\n";                                                  
            echo $ATTACH."\n\n";                                            
            $message = Swift_Message::newInstance()                         
                    ->setSubject($SUBJECT)                                  
                    ->setFrom(array($FROM ))                                
                    ->setTo(array($TO))                                     
                    ->setBody($letter)                                      
                    ->addPart($letter, 'text/html')   
                   ->attach(Swift_Attachment::fromPath($ATTACH)); 
           $mailer=Swift_Mailer::newInstance($transport);         
           $result = $mailer->send($message);                     
           echo $result."\n";                                     
       }                                                          
       if (!feof($handle)) {                                      
           echo "Error: unexpected fgets() fail\n";               
       }                                                          
       fclose($handle);                                           
                                                                  
    ?>

  7. #7
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    I have zero caffeine in my system so help me out here... the main changes are the way in which the recipients and attachments are handled, right?
    George
    Home | Blog

  8. #8
    Join Date
    Sep 2009
    Location
    Ontario
    Posts
    1,057
    Provided Answers: 1
    Quote Originally Posted by gvee View Post
    I have zero caffeine in my system so help me out here... the main changes are the way in which the recipients and attachments are handled, right?
    The only other difference is that yesterday was a statutory holiday.

Posting Permissions

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