Created
June 5, 2017 18:14
-
-
Save danielbachhuber/e0b39ae91a6a2b7ab79232df145f8b5a to your computer and use it in GitHub Desktop.
Thrash APCu until it can no longer allocate memory
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 | |
/** | |
* Thrash APCu until it can no longer allocate memory | |
*/ | |
header("Cache-Control: no-cache, no-store, must-revalidate"); | |
header("Pragma: no-cache"); | |
header("Expires: 0"); | |
$i = 0; | |
$multiple = 200; | |
while( true ) { | |
$i++; | |
$rand = rand( 40, 100 ); | |
$data = str_pad( 'a', $rand * $multiple, 'b' ); | |
apcu_store( "thrash_{$i}", $data ); | |
if ( $i && $i % 10 ) { | |
apcu_delete( 'thrash_' . ( $i - 8 ) ); | |
} | |
if ( $i && $i % 50 ) { | |
$info = apcu_cache_info( true ); | |
if ( $info['mem_size'] > 100000000 ) { | |
$multiple = 2; | |
} elseif ( $info['mem_size'] > 70000000 ) { | |
$multiple = 4; | |
} else { | |
$multiple = 200; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment