In general, the PHP array memory utilization is only 1/10, that is, a C language inside the 100M memory array, in PHP will be 1G.
Especially in the system of PHP as a background server, often the problem of memory consumption is too big.
Because this is a language problem, the general scheme is difficult to solve. The following is a scenario that is resolved by using string.
Code
$total = 100000;
$double = "";
for ($i = 0; $i < $total; $i + +)
{
$double. = Pack ("D", $i + 0.1);
}
for ($i = 0; $i < $total; $i + +)
{
Unpack ("@"). ($i * 8). "/d", $double);
}
This example holds an array of double in a string. Then unpack it out at the time of use.
Of course, this can affect performance. Depends on the specific needs.
For example, in this case:
You have 10 arrays, 10M per array (around 1 million data), then 10 will cost 100M of memory.
Plus 10 people concurrency, memory will be severely inadequate.
Then, in 10 arrays, not all of them are used at the same time. You can save them as a string.
Then, when used, unpack a string into an array.