IMAP PHP - Reading contents of 200+ emails

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • shmick30@gmail.com

    #1

    IMAP PHP - Reading contents of 200+ emails

    Hi There,

    I am looping through and reading the body contents of a mail box with
    over 200 emails in it. The script is running very slow and timing out
    after 180 seconds, only getting through about 180 of these emails. Is
    there anyway I can increase the speed of this script? Why is it taking
    so long to loop through all these emails? Code is below:

    if($mailbox= imap_open( "{###.###.#.### :143/imap}mail_box", $a, $b))
    {
    set_time_limit( 180);
    $check = imap_check($mai lbox);
    $message_count = imap_num_msg($m ailbox);

    for ($i=1;$i<=10;$i ++)
    {

    $header = imap_header($ma ilbox,$i);
    $body = imap_body($mail box,$i);
    $message = imap_fetchbody( $mailbox,$i,1);

    $strpos = strripos($messa ge,"textfield3" );
    $prettydate = date("jS F Y", $header->udate);

    echo $prettydate." - ".substr($messa ge, $strpos+13, 8)."<br/>";

    }

    imap_close($mai lbox);
    }
    else echo "no connection";

  • Benjamin

    #2
    Re: IMAP PHP - Reading contents of 200+ emails

    On Jul 2, 6:28 pm, shmic...@gmail. com wrote:
    Hi There,
    >
    I am looping through and reading the body contents of a mail box with
    over 200 emails in it. The script is running very slow and timing out
    after 180 seconds, only getting through about 180 of these emails. Is
    there anyway I can increase the speed of this script? Why is it taking
    so long to loop through all these emails? Code is below:
    Probably most of the delay is network latency. How fast is your
    connection?
    >
    if($mailbox= imap_open( "{###.###.#.### :143/imap}mail_box", $a, $b))
    {
    set_time_limit( 180);
    $check = imap_check($mai lbox);
    $message_count = imap_num_msg($m ailbox);
    >
    for ($i=1;$i<=10;$i ++)
    {
    >
    $header = imap_header($ma ilbox,$i);
    $body = imap_body($mail box,$i);
    $message = imap_fetchbody( $mailbox,$i,1);
    >
    $strpos = strripos($messa ge,"textfield3" );
    $prettydate = date("jS F Y", $header->udate);
    >
    echo $prettydate." - ".substr($messa ge, $strpos+13, 8)."<br/>";
    >
    }
    >
    imap_close($mai lbox);}
    >
    else echo "no connection";

    Comment

    • Mr Skimpy

      #3
      Re: IMAP PHP - Reading contents of 200+ emails

      On Jul 3, 11:43 am, Benjamin <musiccomposit. ..@gmail.comwro te:
      On Jul 2, 6:28 pm, shmic...@gmail. com wrote:Hi There,
      >
      I am looping through and reading the body contents of a mail box with
      over 200 emails in it. The script is running very slow and timing out
      after 180 seconds, only getting through about 180 of these emails. Is
      there anyway I can increase the speed of this script? Why is it taking
      so long to loop through all these emails? Code is below:
      >
      Probably most of the delay is network latency. How fast is your
      connection?
      >
      We have an internal gigabit connection, so I don't think that will be
      a problem...

      Comment

      • Richard

        #4
        Re: IMAP PHP - Reading contents of 200+ emails


        <shmick30@gmail .comwrote in message
        news:1183418921 .335848.66310@o 11g2000prd.goog legroups.com...
        Hi There,
        >
        I am looping through and reading the body contents of a mail box with
        over 200 emails in it. The script is running very slow and timing out
        after 180 seconds, only getting through about 180 of these emails. Is
        there anyway I can increase the speed of this script? Why is it taking
        so long to loop through all these emails? Code is below:
        >
        if($mailbox= imap_open( "{###.###.#.### :143/imap}mail_box", $a, $b))
        {
        set_time_limit( 180);
        $check = imap_check($mai lbox);
        $message_count = imap_num_msg($m ailbox);
        >
        for ($i=1;$i<=10;$i ++)
        {
        >
        $header = imap_header($ma ilbox,$i);
        $body = imap_body($mail box,$i);
        $message = imap_fetchbody( $mailbox,$i,1);
        >
        $strpos = strripos($messa ge,"textfield3" );
        $prettydate = date("jS F Y", $header->udate);
        >
        echo $prettydate." - ".substr($messa ge, $strpos+13, 8)."<br/>";
        >
        }
        >
        imap_close($mai lbox);
        }
        else echo "no connection";
        >
        Hi NoName,

        I would open the connection, read all needed info, close the connection and
        only then do the processing.

        Other things:
        How long does the script take if you only read headers and nothing else?
        (Try to simplify the script to narrow down the problem)
        Why are you reading the message body twice? (First the full body, and then
        the first body section?)
        How big are the messages?
        This is not the real script, is it? (Or is there some reason you do only 10
        messages that I dont see?)

        Richard.


        Comment

        • Mr Skimpy

          #5
          Re: IMAP PHP - Reading contents of 200+ emails

          On Jul 4, 8:54 am, "Richard" <root@localhost wrote:
          <shmic...@gmail .comwrote in message
          >
          news:1183418921 .335848.66310@o 11g2000prd.goog legroups.com...
          >
          >
          >
          >
          >
          Hi There,
          >
          I am looping through and reading the body contents of a mail box with
          over 200 emails in it. The script is running very slow and timing out
          after 180 seconds, only getting through about 180 of these emails. Is
          there anyway I can increase the speed of this script? Why is it taking
          so long to loop through all these emails? Code is below:
          >
          if($mailbox= imap_open( "{###.###.#.### :143/imap}mail_box", $a, $b))
          {
          set_time_limit( 180);
          $check = imap_check($mai lbox);
          $message_count = imap_num_msg($m ailbox);
          >
          for ($i=1;$i<=10;$i ++)
          {
          >
          $header = imap_header($ma ilbox,$i);
          $body = imap_body($mail box,$i);
          $message = imap_fetchbody( $mailbox,$i,1);
          >
          $strpos = strripos($messa ge,"textfield3" );
          $prettydate = date("jS F Y", $header->udate);
          >
          echo $prettydate." - ".substr($messa ge, $strpos+13, 8)."<br/>";
          >
          }
          >
          imap_close($mai lbox);
          }
          else echo "no connection";
          >
          Hi NoName,
          >
          I would open the connection, read all needed info, close the connection and
          only then do the processing.
          >
          Other things:
          How long does the script take if you only read headers and nothing else?
          (Try to simplify the script to narrow down the problem)
          Why are you reading the message body twice? (First the full body, and then
          the first body section?)
          How big are the messages?
          This is not the real script, is it? (Or is there some reason you do only 10
          messages that I dont see?)
          >
          Richard.- Hide quoted text -
          >
          - Show quoted text -
          The real script does the whole $message_count which is up to over 300
          now. We are expecting about 500. The emails are about 20k each and
          just have user submitted form data. I am reading out a userid value so
          we have a collection of all people which have entered a survey.

          Ahh, forgot to comment out the previous body line. I found I could
          access specific body information with only imap_fetchbody. I will run
          some more tests and see how I go.

          Comment

          Working...