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.
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 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";
?>
For code1 :
1.can download all the emails.
2.output 2465 on the console
3.no over
output on the console.
4.the program can't stop ,it seems to 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 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";
?>
For code2:
1.can download all the emails.
2.output 2465 on the console .
3.over
output on the console.
4.the program stop after download all the emails.
There is one line echo $email_id.PHP_EOL;
in code2 more than code1,other codes are same.
All code1 and code2 are run in command line mode.
Who can explain it ?
strace
then and look what the last syscall(s) are. – bwoebi Jun 28 '15 at 2:43$emails
array or see the count of it to ensure that it doesn't have any blank entries in it? – Dharam Jun 30 '16 at 20:49