Created
December 13, 2015 08:17
-
-
Save mikegioia/0ca42cd9cb2cd569deed to your computer and use it in GitHub Desktop.
Memory allocation leak in imap_fetchheader
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$email = "[email protected]"; | |
$password = "password123" | |
$folder = "INBOX"; | |
$imapStream = imap_open( | |
"{imap.gmail.com:993/imap/ssl}$folder", | |
$email, | |
$password ); | |
if ( ! $imapStream ) { | |
echo "Error: ", imap_last_error(), PHP_EOL; | |
exit( 1 ); | |
} | |
// For each mail ID call fetch headers and check the VSZ | |
// Use args sz,rss,vsz for more info. | |
$pid = getmypid(); | |
$message = <<<STR | |
My PID is: $pid | |
Run this in another terminal: | |
$> watch -n 1 ps -o vsz $pid | |
STR; | |
echo $message; | |
for ( $i = 9; $i >= 1; $i-- ) { | |
echo "\r$i"; | |
sleep( 1 ); | |
} | |
echo "\rStarting...", PHP_EOL; | |
// Search the folder for mail IDs | |
$mailIds = imap_search( $imapStream, 'ALL', SE_UID, 'UTF-8' ); | |
$count = count( $mailIds ); | |
echo "Start Memory: ", memory_get_usage( TRUE ), ", "; | |
echo "Start Peak: ", memory_get_peak_usage( TRUE ), PHP_EOL; | |
foreach ( $mailIds as $mailId ) { | |
echo "\rMailID: $mailId / $count, "; | |
echo "Memory: ", memory_get_usage( TRUE ), ", "; | |
echo "Peak: ", memory_get_peak_usage( TRUE ); | |
$headers = imap_fetchheader( $imapStream, $mailId, FT_UID ); | |
$headers = NULL; | |
unset( $headers ); | |
usleep( 100000 ); | |
} | |
echo "\n\nDone!\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment