PHP array memory consumption too much how to solve

Source: Internet
Author: User
Tags unpack
In general, the memory utilization of the PHP array is only 1/10, that is, a C language inside the 100M memory array, in PHP 1G is necessary. In particular, in the system of PHP as a background server, there are often problems with memory costs too much. Because this is a language problem, conventional solutions are more difficult to solve. The following is a scenario that is solved by string.

$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 saves an array of double strings with a string. Then unpack out when it's in use.
Of course, this can affect performance. To see the specific needs.
For example, in this case:
You have 10 arrays, each of which is 10M (about 1 million data), then 10 takes 100M of memory.
Plus 10 people in parallel, the memory will be serious enough.
Then, in 10 arrays, not all are used at the same time. You can, save them as a string and then, when used, unpack a string into an array.

Related recommendations:

PHP Array Memory Utilization Low detailed analysis

PHP array memory consuming too many problems solution _php

Resolving PHP array memory consumption too much

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.