PHP array memory consumption too much problem solution. Because this is a language problem, it is difficult to solve conventional solutions. The following is a solution using string. Copy the code as follows: $ total100000; $ double; for ($ I is difficult to solve because it is a language problem. The following is a solution using string.
The code is as follows:
$ 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 uses a string to save an array of double. And then unpack it during use.
Of course, this will affect performance. Depends on the specific requirements.
For example:
You have 10 arrays, each of which is 10 MB (about 1 million data records), so the ten arrays will spend MB of memory.
With the addition of 10 concurrent users, the memory will be severely insufficient.
Then, it is not used at the same time in 10 arrays. You can save them as strings.
Then, when used, unpack a string into an array.
Bytes. The following is a solution using string. The code is as follows: $ total = 100000; $ double = ""; for ($ I =...