通过PHP检查Gmail IMAP以获取循环中的新消息 [英] Check Gmail IMAP via PHP for new messages in a loop

查看:103
本文介绍了通过PHP检查Gmail IMAP以获取循环中的新消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究一个应用程序,以基于到达Gmail的新IMAP电子邮件触发PHP脚本。知道新电子邮件的最佳方式是通过Gmail IMAP帐户获得的?我想不出什么,但配置一个cron作业。我在Linux(Ubuntu)盒子上运行PHP + Nginx。

解决方案

我发现这只是celular公司开发者正在做验证他们的客户gmail。



好吧,开始建立连接normaly,然后:

  $ t1 = time(); //将时间标记为
$ tt = $ t1 +(60 * 1); //总时间= t1 + n秒
$ b $ ($ set($ t2))unset($ t2); //在每个循环清理它cicle
$ t2 = time(); //标记时间
if( imap_num_msg($ imap)!= 0){//如果有任何消息(在收件箱中)

$ mc = imap_check($ imap); //消息检查
// var_dump ($ MC); die; //用vdump来查看imap_check()可能获得的所有数据,并为它们自己定制它


} else else'没有新的消息';

sleep(rand(7,13)); //如果(!@ imap_ping($ imap)){//如果连接不是$ b,则给Google服务器一个breack
$ b //以最初的
}

}的方式启动imap连接(($ tt> $ t2); //如果总时间还没有启动,回到循环的开始处

就是这样。

顺便说一句,以下是关于IMAP如何运作的一些很好的信息。我的观点是:因为IMAP使得实际上可以实现一种实时同步连接,所以如果你不想配置一个MTA来接收电子邮件(像我一样),所以IMAP是一个真正的选择,可以让电子邮件发生故障b
$ b


  • 每次连接到电子邮件时,连接会保持活动状态5到10分钟,除非您手动断开连接

  • Gmail确实将每个帐户限制为10个并发连接。

  • 然而,一个IMAP帐户应该检查邮箱,然后保持一个活动频道到达IMAP服务器(IMAP-IDLE),预设行业标准为29分钟,然后超时。如果您将自动恢复设置设置为20-30分钟,那么应该让手机连接到远程IMAP框。

  • 当GMAIL收到一封电子邮件时,它应该向IMAP空闲会话和mobiPush应该几乎立即提取。

  • 所有计划每10分钟检索一次Gmail邮件,该选项会在到达Gmail服务器时立即同步传入的电子邮件。


I am studying an application to trigger a PHP script based on new IMAP emails arriving on Gmail. What's the best way to know a new email has arrived on a Gmail IMAP account? I can't think of anything but to configure a cron job. I am running PHP + Nginx on a Linux (Ubuntu) box.

解决方案

I found out that that's just the way celular companies developers are doing to verify their clients gmail.

Well, start making the connection normaly, 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

And that's it.

By the way, here's some good informations about how IMAP works. My point is that: as IMAP makes possible to mantain virtually a kind of "Live Sync" connection, if you don't want to configure a MTA to receive email (like me), so IMAP is a real option for get "email pusshed" to you.

  • The connection stays active from 5 to 10 minutes each time you connect to your email, unless you manually disconnect
  • Gmail does limit each account to 10 simultaneous connections.
  • An IMAP account, though, shoud check the mailbox and then keep an active channel to the IMAP server (IMAP-IDLE) for the preset industry standard of 29 minutes before it times out. If you set your Auto-Retrieve setting to between 20-30 minutes, that should keep your phone connected to the remote IMAP box.
  • When GMAIL gets an email it should send a response to the IMAP idle session and mobiPush should pick it up almost instantly.
  • All schedule to retrieve your Gmail mail every 10 minutes, this option will sync incoming E-mail immediately when it arrives at the Gmail servers.

这篇关于通过PHP检查Gmail IMAP以获取循环中的新消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆