php - What's the most efficient way to sort through emails with zend_mail? -
i'm sorting through emails looking specific instances of strings , taking long. time down half second per email, , it's taking 2-2.5 seconds per email.
i'm worried i'm doing dumb that's slowing down - mysql or zend_email. code checks user's inbox specific phrase "chocolate", returns values jquery ajax function. loops through ten times (in version, checks 10 emails). if see decrease loading time, appreciated. initially, thought not including libraries helpful, libraries without email opening functions lightning fast.
i'm sure i'm doing dumb , amateurish (maybe few things). please point them out if possible.
here's code...
<?php $storage = new zend_mail_storage_imap($imap); $x=0; while($x<10) { $flags = $storage->getmessage($i)->getflags(); if(!empty($flags['\seen'])) { $read=1; } else { $read=0; } if (strpos($storage->getmessage($i),'chocolate') !== false ) { $fromaddress = str_replace("'","",$storage->getmessage($i)->from); $fromaddress = str_replace('"','',$fromaddress); $sql = "select `senderemail`,`subscribed` email_spam `useremail` = '$_session[email_address]' , `senderemail` = '$fromaddress'"; $result = mysql_query($sql) or die (mysql_error()); $num = mysql_num_rows($result); if($num == 0) { $emailmessage = mysql_escape_string($storage->getmessage($i)->getcontent()); $sql_insert = "insert `email_spam` (`message`,`useremail`,`senderemail`,`datetime`,`subscribed`) values ('$emailmessage','$_session[email_address]','$fromaddress',now(),1)";// echo $sql_insert; mysql_query($sql_insert,$link) or die("insertion failed:" . mysql_error()); $sql = "select `emailid`,`datetime` email_spam `useremail` = '$_session[email_address]' order `datetime` desc"; $getid = mysql_query($sql) or die (mysql_error()); $num = mysql_num_rows($getid); echo '<tr><td>'. $fromaddress . '</td>'; echo '<td class="unsubscribe_td" align="center"><input type="submit" value="unsubscribe me" class="unsubscribe_button" id="'. mysql_result($getid,0,'emailid') .'"/></td></tr>'; } } if ($read==0) { $storage->setflags($i, array(zend_mail_storage::flag_recent)); //marks new } $i--; $x++; } ?>
there's no point in profiling - it's wrong approach. you're doing separate imap request , data transfer every message, never fast. efficient way not here @ - imap server search you. it's not quite flexible you're doing, have no trouble searching tens of thousands of messages per second, , can simple string match in message bodies. php has support searching inboxes in imap extension. don't know if function exposed via of zend components, doesn't matter if isn't.
this mechanism iphone inbox search uses; local search on messages has, offers option continue search on server, hands-off that's got data , has more horsepower bring bear.
Comments
Post a Comment