What's faster - grabbing the image from folders or grabbing the image of a URL?


I've always debated this in my head and now would like some input from you guys at stack. So what is faster?

I can see that grabbing images from files are probably the fastest since it's local, but the process of finding the files through folders and picking the right one would probably use up the most processing power.

Grabbing a image from url could simply be sending a request to the url and downloading that image. While the image is downloading, other parts of your website is loading.

When loading a page, how does the server run one (or few) processing threads to build the page? Does a page get built in a procedural fashion (building one thing at a time as apposed to running everything at the same time)? Could this be the difference of procedural PHP (Wordpress) and object oriented PHP (Codeigniter)?

When you get file via url you need to connect to server. Now you have two cases:

  1. Server is local
  2. Server is external

If server is local then you may use local IP which won't cause DNS to resolve adress and it's pretty fast but server is involved.

If the server is extarnal then you need to use either domain or ip if you know it. You need to calculate the speed of connection and speed of server but in my personal opinion this is not good solution.

About using files. You wrote that you have URL which exactly defines where the file is. You can do the same with files and give the path so there's no need to find the file just to download it. I'm certain it's faster solution.

About Wordpress and Codeigniter it's still PHP so it depends how the code is used. Obviosly you can write stupid function that looks in entire server to find a file or you can specify where it should be or you can give a path to it. So it's faster. There are also nice solutions in PHP to search for files and handle them. For example iterators or simple glob() function.

To conclude, my opinion is that using files instead urls is better solution.