Fastest way to upload many images in PHP 5.3?

Im working on a script that integrates online shopping.

I have code like this (simplified):

// $asImageurls - array of string with image url's foreach($asImageurls as $sImageUrl) { $imageContent = @file_get_contents($image); // create filename, save image etc. } 

Connecting to a remote server, uploading an image takes a lot of time, and this is not very good when I need to import 500 products.

I was thinking about parallel loading, but I do not know how to start.

What can I do to make it faster?

+4
source share
1 answer

There are two main solutions to this problem:

1) Instead of uploading images directly, save all the URLs in a file (also the final destination path). Then use cron to invoke the script every n minutes, which will download for you. This is the best way to avoid server overload if many users send orders at the same time.

2) Use the exec () function of PHP. Thus, you can invoke any required system command. Usually curl in your case. That way you can add and toss it at the end in the background. You can even store warnings and errors by redirecting them to a file.

0
source

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


All Articles