php - why the program can't stop after downloaded all the emails? -


there 2465 emails in gmail,why program can't stop after download emails? code1 , code2 run in command line mode.
code1:

<?php $mailbox = array(     'mailbox'  => '{imap.gmail.com:993/imap/ssl}inbox',     'username' => 'xxxx@gmail.com',     'password' => 'yyyy' );  $stream = imap_open($mailbox['mailbox'], $mailbox['username'], $mailbox['password'])     or die('cannot connect mailbox: ' . imap_last_error()); $emails = imap_search($stream,"all"); $nums=imap_num_msg($stream); echo $nums; foreach($emails $email_id) {              $mime = imap_fetchbody($stream, $email_id, "");             file_put_contents("/tmp/" . "email_{$email_id}.eml", $mime);         }  imap_close($stream); echo "over"; ?> 

for code1 :
1.can download emails.
2.output 2465 on console
3.no over output on console.
4.the program can't stop ,it seems run forever.

code2:

<?php $mailbox = array(     'mailbox'  => '{imap.gmail.com:993/imap/ssl}inbox',     'username' => 'xxxx@gmail.com',     'password' => 'yyyy' );  $stream = imap_open($mailbox['mailbox'], $mailbox['username'], $mailbox['password'])     or die('cannot connect mailbox: ' . imap_last_error()); $emails = imap_search($stream,"all"); $nums=imap_num_msg($stream); echo $nums; foreach($emails $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"; ?> 

for code2:
1.can download emails.
2.output 2465 on console .
3.over output on console.
4.the program stop after download emails.

there 1 line echo $email_id.php_eol; in code2 more code1,other codes same.
code1 , code2 run in command line mode.
can explain ?

enter image description here

try

print imap_last_error(); 

before , after imap_close know more causes problem


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -