Shared Memory - Essais02

Shared Memory - Essais02

'; $SHM_KEY = getShmKey(); $size = 1024*1024 ; for( $i=0; $i<60; $i++) { $size=intval($size); if( $size==0 ) break; $data = shm_attach( $SHM_KEY, $size, 0600); if( $data == null || $data === FALSE) { echo 'FAILED for size='.formatBytesSize($size)."\n"; break; } else { echo 'OK for size='.formatBytesSize($size)."\n"; shm_remove($data); shm_detach($data); } $size += 1024*1024 ; } echo ''; } /** * @parame int $sizeInBytes * @return string */ function formatBytesSize( $sizeInBytes, $afterColon=2) { // less than 1kB if($sizeInBytes < 1024) { return $sizeInBytes . ' B'; } // between 1kB and 1MB if ($sizeInBytes >= 1024 && $sizeInBytes < 1048576) { return number_format( $sizeInBytes / 1024, $afterColon) . ' KB'; } // between 1MB and 1GB if ($sizeInBytes >= 1048576 && $sizeInBytes < 1073741824) { return number_format( $sizeInBytes / 1048576, $afterColon) . ' MB'; } // more than 1GB return number_format( $sizeInBytes / 1073741824, $afterColon) . ' GB'; } ?>