Such a problem arose: From the database I made the export of the table into a PHP array. Also in the online store there are about 50K items. The table that was exported from another online store, and accordingly the names of the fields are different. It is necessary to write a script that will assign the required fields from the array to the commodity items. The goods and the array have a common property “article” - the values ​​of which coincide. It is necessary to sort through all the goods, take the article from the i-th product and look for its array and assign values ​​from the array to the product.


Now the question: File with an array in a separate file, its size is huge, how to connect it to the script, what would be easier to work (the script worked faster), via include or require ? You will also have to change the script execution timeout. Is it possible to work with this array at all, or is it better to do sql queries? What can you advise? Only the database itself is located on another server and the work will be performed on another one.

  • with a base it is easier to check and sample right on the base - Naumov
  • Well, of course, you can fully connect if there is a lot of memory and the memory limitations in php.ini are quite high, but keep in mind that this array will be larger in memory than the file size at times. Better stream processing - tutankhamun
  • one
    The console scripts time is not limited. Work clearly disposable. What is the difference, in 5 minutes the script will work, or in 10? - Ipatyev
  • @aat A "array" which is in your file in what format? how do you expand it into an array in php? - Mike

3 answers 3

No matter how the php file will cling, the memory will be eaten in order. It is better to return to the stage earlier in the direction of the database. If I understand correctly, there is already a database in which 2 tables - old (old) and new products (new).

The easiest way is to sql query:

 UPDATE new JOIN old ON new.art=old.articul SET new.name = old.naimenovanie, new.desc = old.description, new.count = old.count+new.count 

Here is a basic example, it will merge according to the articles, any fields can be directly prescribed - what and where.

    If you need to run one-time for processing, it is easier to run as a cli script, after increasing the memory for php: ini_set ('memory_limit', '1024M');

    Although if you managed to make an export, then there should be enough memory.

    include or require does not matter.

      In general, no matter what way to connect, it will take a lot of memory. If there is an allowed memory size error, then place one or both arrays in the database, in the two tables prepared in advance and work with them already line by line. Slower will be due to requests and updates but significantly less memory requirements will be.