I wrote the parsing of goods for the online store, but there was a problem: A large number of images (about 1000) need to be uploaded to the server (each has its own link) while reducing their weight (because they weigh 2-8 MB) to 200 500 kb. Tell me how to do this so that the script does not overload the RAM
- Specify what the problem is. You have already implemented image upload to the server and want to optimize it? - koks_rs
- @koks_rs Yes, the download is already implemented. I use curl to load an image into a class (temporary file), then resize it, and save it to the server, but this method overloads the RAM, and the script does not have time to finish, not all images are loaded. - Vyacheslav Fedorov
- Is this your server? - Crantisz
- @Crantisz no, hosting - Vyacheslav Fedorov
3 answers
You can use online services like rsz.io , kraken.io, and others, which will give you a modified image; and yes, please do not raise the question . Last alternative - free service from Google ( description in English here )
You need to separate lokiku. First parse all the images as they are. And only when the catalog is drawn, trim each one in the product withdrawal cycle. Well, or as an option post images of goods from the source.
- The size of the pictures at the source is large, the pages load for a long time, and the process of cutting the picture when loading the catalog will not slow down the page loading? - Vyacheslav Fedorov
- I do not think. You do not display the entire catalog of goods at once? Most likely with pagination and goods 50-100 per page. I work with opencards, and there lokika processing from the following: turned to the picture during the formation of the array of goods, processed on the fly, push into the subarray of the goods. Along the way, keshnuv, but the "motor" itself is doing this. definitely one thing - parsing and at the same time processing and outputting is not very good) - Kirill Korushkin
- And what function do you process the picture? - Vyacheslav Fedorov
- imagecreatetruecolor - Kirill Korushkin
- probably, it is necessary to learn more: when uploading a picture to the server, we pull imagecreatetruecolor to create a picture with dimensions specified in the config (for tambs, photo in the catalog, product maps, etc. for all its dimensions). And save two: the original and a copy. And already when a client requests, for example, a catalog, when forming an array of goods, altered images are taken if they are created earlier, or thumbnails are created on the fly by the same classes. This is in general. More specifically, only by the example of classes open chart. - Kirill Korushkin
Try to increase the amount of memory allocated for the script:
<? ini_set('memory_limit', '512M'); So, perhaps, not enough time:
<? set_time_limit(500); However, if this does not help (for example, hosting will not install enough), you will have to copy the images in batches of 10,000, 1,000, or 100 each.