title: why the program can't stop after downloaded all the emails?
body: <p>There are 2465 emails in my gmail,why the program can't stop  after download all the emails?  All code1 and code2 are run in command line mode.<br>
  code1:  </p>
  
  <pre><code>&lt;?php
  $mailbox = array(
      'mailbox'  =&gt; '{imap.gmail.com:993/imap/ssl}INBOX',
      'username' =&gt; 'xxxx@gmail.com',
      'password' =&gt; 'yyyy'
  );
  
  $stream = imap_open($mailbox['mailbox'], $mailbox['username'], $mailbox['password'])
      or die('Cannot connect to mailbox: ' . imap_last_error());
  $emails = imap_search($stream,"ALL");
  $nums=imap_num_msg($stream);
  echo $nums;
  foreach($emails as $email_id) {
  
              $mime = imap_fetchbody($stream, $email_id, "");
              file_put_contents("/tmp/" . "email_{$email_id}.eml", $mime);
          }
  
  imap_close($stream);
  echo "over";
  ?&gt;
  </code></pre>
  
  <p>For code1 :<br>
  1.can download all the emails.<br>
  2.output 2465 on the console<br>
  3.no <code>over</code> output on the console.<br>
  4.the program can't stop ,it seems to run forever.   </p>
  
  <p>code2:  </p>
  
  <pre><code>&lt;?php
  $mailbox = array(
      'mailbox'  =&gt; '{imap.gmail.com:993/imap/ssl}INBOX',
      'username' =&gt; 'xxxx@gmail.com',
      'password' =&gt; 'yyyy'
  );
  
  $stream = imap_open($mailbox['mailbox'], $mailbox['username'], $mailbox['password'])
      or die('Cannot connect to mailbox: ' . imap_last_error());
  $emails = imap_search($stream,"ALL");
  $nums=imap_num_msg($stream);
  echo $nums;
  foreach($emails as $email_id) {
              echo  $email_id.PHP_EOL;
              $mime = imap_fetchbody($stream, $email_id, "");
              file_put_contents("/tmp/" . "email_{$email_id}.eml", $mime);
          }
  
  imap_close($stream);
  echo "over";
  ?&gt;
  </code></pre>
  
  <p>For code2:<br>
  1.can download all the emails.<br>
  2.output 2465 on the console .<br>
  3.<code>over</code> output on the console.<br>
  4.the program stop after download all the emails.</p>
  
  <p>There is one line <code>echo  $email_id.PHP_EOL;</code>  in code2 more than code1,other codes are same.<br>
  All code1 and code2 are run in command line mode.<br>
  Who can explain it ?</p>
  
  <p><img src="https://i.stack.imgur.com/4TNTW.png" alt="enter image description here"></p>