📜 ⬆️ ⬇️

PHPShop Optimization

It so happened that one of our customers ordered us to add to his online store several tens of thousands of products. His shop worked at the well-known PHPShop (version 2.1.8) . Up to this point, I have not met with this "miracle". After adding the first 5000 products, the store came down and could show only a white page. Those support answered that it was all because of the host (MasterHost). I believed them and decided to try everything on a local web server. The store showed the same picture. Moreover, the task list showed that Apache “eats” 200 MB of RAM. I had to climb into the inside ...

After a brief search, it was found that when displaying goods, the script did not query the database to get a specific product. It turned out that when you run the script, all the goods from the database are placed in the global array, and then, when you need a certain product, it was taken from this array. And for some reason, the module, which in theory should be responsible for caching (cache.inc.php), was doing this. It seemed to me very strange. To rewrite the whole script so that the data was taken from the database only when it was needed, it took a long time (this global array was used very often) and there was no time, because the customer was in a hurry. We had to look for another way out and it was found.

It was necessary to make the data in the array fall only when accessing it. After a brief search, the ArrayAccess interface was found, which allows the object to be accessed as an element of an array. For a couple of hours it was all implemented. Now the data in the array fell only when accessing it. Also, in addition, all the received data was cached to avoid loading MySQL server.

Solving the problem not only restored the store’s performance, but also reduced the page generation time by a factor of two.
')
If someone is interested in looking at the code for solving a problem, I can publish it in its entirety in the next post.

If the developers of PhpShop see this post, I would like to know what they were guided by, creating a global array with all the goods in advance.

Source: https://habr.com/ru/post/62470/


All Articles