Hello. There is an online store on the engine PhpShop 3.1 . There are about 2500 goods in it. He eats more than 200 MB and the hoster for it kicks.
The problem is that from the start he does not select the necessary goods from the database, but takes EVERYTHING and puts them into an array, which he refers to in the future.
Here is a graph of memory usage:

memory usage graph

It is necessary to optimize it.
Here found an article on Habré: Optimization PHPShop
I want to do the same, but I do not understand how they achieved that the data would fall into the array only when they were accessed?
This should be done "unnoticed" for other scripts, i.e. they will continue to turn to the array as before, so as not to pick the whole engine.

Tell me what is meant in the article and how to do it.

UPD:

PhpInfo: info - ancient php 4.4.9 ((
Here are all the statistics for the last year: stat

  • Ideal - change the engine. It is foolish to pay for what you have to finish. As for the article, then, IMHO, they changed the way of forming the array, turning it into an object that requests data from the database for the desired index only when accessing this index. I cannot tell the implementation details - I haven't worked with phpshop for a long time. But I suppose that, having studied the capabilities of the ArrayAccess interface ( ru2.php.net/manual/en/class.arrayaccess.php ), you yourself can create a similar “optimization” crutch. - Indifferent
  • @ Indifferent, hmm. Similarly, they climb in the database with each call. I will continue to understand. - Ray

2 answers 2

The graph shows that memory consumption began to grow sharply and suddenly, which indicates either a reached database chunk in size or someone's hooliganism from competitors or multiple image losses and sticking missing images to the wrong 404 error through an index that every time twitches and creates "autominidoss". First, look at the logs for numerous identical IP, then analyze the size of the database through PhpMyAdmin, clear large temporary tables (log table, lookup table). Run the command to optimize the database. Download the latest version from the site and take the .htaccess file and see how it works. In the control panel, turn off the message about new orders / messages. In PHPShop, there are no large arrays for a long time, it accesses the database and selects data only from the specified directory within the paginator limit. The amount of memory consumed by the engine itself can be viewed in the source code at the very end, an example of a database 32 queries ~ 0.0818 sec, 4570.91 Kb. To get 200MB you need a good periodic index index, which can only be in the cases that I described. Another side is the unauthorized intervention of SEO masters, for example, Demis puts his index interceptor with a "regular" and memory consumption increases significantly.

UPD 1 24170 6.82% 16361 5.18% 154405 4.19% 49 0.51% 94.79.54.150 2 18925 5.34% 18380 5.82% 0 0.00% 0 0.00% 212.193.234.171

If these are not your IPs 94.79.54.150, 212.193.234.171 then they should be blocked in .htaccess. Another alarming thing in the log is the record of the transition to the main page from the redirect. Show your .htaccess

  • @Dennion, thanks for such a wide response. On DDos check. That's what's in the database: - logging in phpshop_jurnal (6200 entries) - logging rss in phpshop_rssgraber_jurnal (900 lines) - logging in phpshop_search_jurnal (42000 lines) - photos in phpshop_foto (4700 records) - goods in phpshop_products 24 . Really fixed a sample of all products. Now ALL are selected from one directory, although only 10 are displayed on the page. - Ray
  • On my local computer, memory jumps by 10-20 MB when executing the request. The most resource-intensive operation - the withdrawal of all goods categories. It is also suspicious that there are 2400 products in the database, although in reality there are not so many of them on the site. The amount of consumed memory did not understand where to look (In the source of the page at the end there is: "StNF 74 ~ 0.3386" - is it? - Ray
  • one
    1. The table of the search log was clogged for 4 years, you need to clear it execute TRUNCATE phpshop_search_jurnal; TRUNCATE phpshop_jurnal; 2. perform OPTIMIZE TABLE .... You need to look at the logs, there are good souls starting to choke pages / search / /shop/CID_XXX_ALL.html For them, you need to immediately add an exception to the IP in .htaccess, for example, deny from 157.55.36.36 deny from 157.55.32.109 StNF 74 ~ 0.3386 - this is 74 queries to the database and execution in 0.3 seconds. In principle, it is tolerable. - Dennion
  • one
    You also need to look at the option of mixing on the ftp virus, especially in the root files like bd.php or image.php with a fresh change date (judging by the schedule - March 2013). In addition to the site of the store, there are no other sites on this account, are there Joomla or forums? - Dennion
  • one
    For logging, you can create a function to write to the file. Memory is allocated like this // Memory consumption if (function_exists ('memory_get_usage')) {$ mem = memory_get_usage (); $ _MEM = round ($ mem / 1024, 2). "Kb,"; } else $ _MEM = null; Further $ _MEM to write in memory.txt but, the one that you showed the file usually give hosting nic.ru, beget.ru, they show the load of Apache + php. Php overload cannot be separated from this graph separately. And the Apache can be beaten and twitching static html. Logs need to watch. If there is statistics on the logs, then pay attention to the most popular files. - Dennion

@Dennion , updated the main post.