PhpWhen the script is running, the data is stored in the memory,ArrayAndMysqlThe result set is a common data type. The memory usage of the two data types is tested.
Research and useMemory_get_usage (true)View memory usage
ForArrayType,KeyAndValueWhen all are integers, the size is1 MArray, memory usage is about136 M, Average per record136Bytes.
ForArrayType,KeyIs an integer,ValueIs the length128String, the size is1 MArray, memory usage is about288 M, Average per record288Bytes.
KeyType |
ValueType |
Array size |
Memory usage |
Average |
Int |
Int |
1 M |
136 M |
136 |
Int |
String (4) |
1 M |
168 M |
168 |
Int |
String (128) |
1 M |
288 M |
288 |
String (16) |
Int |
1 M |
152 M |
152 |
|
|
|
|
|
From the test above, adding a record to the array requires additional data storageAbout100BytesTo maintainHashTable information.(ZvalStorage integer approx.9Bytes?)
It is worth noting that,MysqlThe result set cannot be stored throughMemory_get_usageThe function is not counted.PhpMemory limit of the script. Pay attention to this feature when writing scripts for reading big data.
Data volume,MyIsamMedium. MYDThe file size is1.2 GBThe sum of all result sets exceeds4G.