Check Gmail IMAP via PHP for new messages in a loop

I am studying an application to run a PHP script based on the new IMAP emails arriving in Gmail. What is the best way to get a new email sent to your Gmail account in IMAP format? I can't think of anything but to configure cron to work. I am running PHP + Nginx on Linux (Ubuntu).

+3
source share
2 answers

I found out exactly what the developers of celular companies do to test their gmail clients.

Well, start normalizing the connection, then:

$t1=time();//mark time in
$tt=$t1+(60*1);//total time = t1 + n seconds

do{
    if(isset($t2)) unset($t2);//clean it at every loop cicle
    $t2=time();//mark time
    if(imap_num_msg($imap)!=0){//if there is any message (in the inbox)

        $mc=imap_check($imap);//messages check
        //var_dump($mc); die;//vardump it to see all the data it is possible to get with imap_check() and them customize it for yourself


    }else echo 'No new messagens';

    sleep(rand(7,13));//Give Google server a breack
    if(!@imap_ping($imap)){//if the connection is not up
        //start the imap connection the normal way like you did at first
    }

}while($tt>$t2);//if the total time was not achivied yet, get back to the beginning of the loop

What is it.

, , IMAP. , , IMAP - "Live Sync", MTA (, ), IMAP - " pusshed" ".

  • 5 10 ,
  • Gmail 10 .
  • IMAP IMAP (IMAP-IDLE) 29 . Auto-Retrieve 20-30 , , IMAP.
  • GMAIL , IMAP, mobiPush .
  • Gmail 10 , Gmail.
+4

, , (, cron-job) , PHP script.

Zend_Mail, Zend Framework Zend_Mail_Storage_Imap ( MVC), Gmail, .

+1

All Articles