Problems with PHP System_Daemon and IMAP connection.

Posted by mike on Stack Overflow See other posts from Stack Overflow or by mike
Published on 2010-06-02T14:46:57Z Indexed on 2010/06/02 15:13 UTC
Read the original article Hit count: 252

Filed under:
|
|

I'm trying to create a PHP daemon that connects to an IMAP server and processes emails as they come in. I have it close to working, but the daemon keeps grabbing the original emails that it finds the first time the daemon is loaded. I believe the reason is because I'm opening the IMAP connection in the parent process. Example below:

if ($imapConnection=imap_open($authhost,$user,$pass) or die())
{
  //start daemon
  while()
  {
    //Grab email headers 
    $imapHeaders = imap_headers($imapConnection);
    $count = sizeof($imapHeaders)

    //loop the emails
    for($i = 1; $i <= $count, $i++)
    {
      //process the email
      //delete the email
    }

    System_Daemon::iterate(15);
  }
}   
imap_close($imapConnection);

I'd like to stay away from putting the IMAP connection within the loop. How can I keep the connection to the IMAP server outside of the loop and still get new emails?

© Stack Overflow or respective owner

Related posts about php

Related posts about imap