indianyogi Posted January 26, 2009 Share Posted January 26, 2009 I have this following code. $mbox = imap_open("{mailbox:143/notls}INBOX", "username", "password") or die(imap_last_error()."<br>Connection Faliure!"); $MC = imap_check($mbox); // Fetch an overview for all messages in INBOX $result = imap_fetch_overview($mbox,"1:{$MC->Nmsgs}",0); echo "<table border='1' cellpadding='5'>"; echo "<caption>Overview Output</caption>"; echo "<tr><th>Msgno</th><th>From </th><th>To</th><th>Subject</th></tr>"; foreach ($result as $overview) { $header = imap_fetchheader($mbox,$overview->msgno); $header = explode('X-Forwarded-For:', $header, 2); $header = explode('myemail@gmail.com', $header[1], -1); $emailTo = $header[0]; echo "<tr><td>#$overview->msgno {$overview->date}</td><td> " . $overview->from . " </td><td>" . $emailTo . "</td><td>$overview->subject</td></tr>"; echo "</table>"; .... For small number of emails, this code works fine. but as soon as message number increase and hits more then 50. Following error is encountered: Maximum execution time of 30 seconds exceeded in imaptest.php My goal is to extract an email just after X-Forwarded-For in imap_fetchheader. I also tried preg_match('/X-Forwarded-For:\s(.*)\smyemail@gmail.com/i',$header,$getText); But this too triggers the same error : Maximum execution time of 30 seconds exceeded in imaptest.php Is there any alternative method to achieve the result with better programming approach. How can make this code more faster .. or say lighter. any alternatives/suggestions ? Quote Link to comment https://forums.phpfreaks.com/topic/142499-how-to-execute-this-code-faster/ Share on other sites More sharing options...
premiso Posted January 26, 2009 Share Posted January 26, 2009 Use a script that supports mass mailing. PEAR Mailer is a good one, you might even consider PHPMailer (not sure if that supports mass mailing). Pear::Mail is your best bet imo. Your other option is to do it in stages, limit the query to 50 emails send. Or use set_time_limit and change the execution time to be more than 30 seconds, however if accessing from a browser the browser may time out. So yea. Look into Pear::Mail for mass mailing Quote Link to comment https://forums.phpfreaks.com/topic/142499-how-to-execute-this-code-faster/#findComment-746715 Share on other sites More sharing options...
MadTechie Posted January 26, 2009 Share Posted January 26, 2009 Hummm i have the stragest feeling that premiso likes Pear::Mail, if you can't use it then a trick i used was a loop that send 100 mails, then auto-refreshed and send the next 100 mails etc etc.. it was a lazy trick but worked for a one off project.. Quote Link to comment https://forums.phpfreaks.com/topic/142499-how-to-execute-this-code-faster/#findComment-746880 Share on other sites More sharing options...
premiso Posted January 26, 2009 Share Posted January 26, 2009 Hummm i have the stragest feeling that premiso likes Pear::Mail, if you can't use it then a trick i used was a loop that send 100 mails, then auto-refreshed and send the next 100 mails etc etc.. it was a lazy trick but worked for a one off project.. No, but I do not know of any other php mass mailer scripts. I actually have my own mailing script that creates a queue that sends 5 messages every 5 seconds that are in queue in my DB via a Cron Job. I found that to work great, but I know that Pear::Mail has that functionality too, it just requires Pear Quote Link to comment https://forums.phpfreaks.com/topic/142499-how-to-execute-this-code-faster/#findComment-746890 Share on other sites More sharing options...
MadTechie Posted January 26, 2009 Share Posted January 26, 2009 Oh don't get me wrong i agree, My 2nd Choice would be phpmailer (due to ease of use) but it is still limited, i have added to it but still limited hence my "workaround", I only said that because you said Pear Mail in 3 out of 4 paragraphs. Quote Link to comment https://forums.phpfreaks.com/topic/142499-how-to-execute-this-code-faster/#findComment-746893 Share on other sites More sharing options...
premiso Posted January 26, 2009 Share Posted January 26, 2009 Oh don't get me wrong i agree, My 2nd Choice would be phpmailer (due to ease of use) but it is still limited, i have added to it but still limited hence my "workaround", I only said that because you said Pear Mail in 3 out of 4 paragraphs. Yea, I get excited when posting and sometimes forget to watch how/what I type Reading that post now I do realize that I was totally promoting Pear::Mail lol. Whoops. Quote Link to comment https://forums.phpfreaks.com/topic/142499-how-to-execute-this-code-faster/#findComment-746897 Share on other sites More sharing options...
indianyogi Posted January 27, 2009 Author Share Posted January 27, 2009 @premiso, and others Thanks. set_time_limit() did the work. My script was taking lil more then 32 seconds. Thanks again to others too .. for valuable contributions Quote Link to comment https://forums.phpfreaks.com/topic/142499-how-to-execute-this-code-faster/#findComment-747340 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.