This extension enables you to host category and product images on a CDN (or any separate server) with ease.
This extension enables you to host category and product images on a separate server with ease. This can improve page load time by offloading some of the stress from your web server and by allowing you to utilize a high performance content delivery network (CDN) or another remote host. If your website has a large amount of traffic, using a CDN will help to bring down your bandwidth cost and speed up your response time. Currently, the extension integrates with Amazon S3, Coral CDN, Mosso/Rackspace Cloud Files, and any CDN, server or service that supports FTP, FTPS, or SFTP. Each adapter has a separate configuration menu with options unique to each. The abstract adapter can be extended to easily add support for any other CDN that has a published API. In this respect, we are always seeking new CDNs to include in this extension as well as community-provided implementations to be added.
The extension automatically distributes category and properly-sized product images to a CDN when they are referenced in the Magento templates. This code extends the functionality of category and product image getUrl() to determine the existence of the file on the CDN, push the image to the correct location if it isn’t found, and return the CDN-specific URL. Installation of this extension into an operational store will work immediately as images already present will be uploaded to the CDN on demand. Because of this, you can install, enable, and disable this extension without consequence and at any time.
Checks for the file’s existence on the CDN are performed using a cURL header request and are cached in the database or file system for a set amount of time to reduce the load time experienced by the end user. In practice, the time to live for the cache is set with a 90% to 110% random variance to lessen the possibility of cache checks being lumped onto a single request. The original image is kept on the web server and is used to generate newly requested permutations of the image at the given height and width values specified in the templates.
The benefit of this extension over Apache-based rewrites is it eliminates requests to the web server. In this respect, returned markup will contain image paths that directly point to the CDN. The extension is intelligent enough to look at the request and determine if HTTP/HTTPS is required and the adapters provided react accordingly. This extension also alleviates the need to write complex rewrite rules in Apache setting files.
The Amazon S3 integration includes and uses the wrapper called PHP-AWS, available at: code.google.com/p/php-aws/. Since Amazon S3 supports both HTTP and HTTPS requests, all URLs returned by that adapter match the protocol in the request.
The Mosso (now called Rackspace Cloud) integration includes and uses the wrapper written by Mosso, available at: api.mosso.com/clients/cloudfiles/php-cloudfiles-1.3.0.zip. Mosso Cloud Files does not support secure requests and as a result, the images requested over HTTPS will be generated, stored, and served from the web server.
Coral CDN is a free, open source, peer-to-peer content distribution network that works simply by appending “.nyud.net” to the hostname of any URL. Images will still be stored and served to the CDN from your local server, but may be cached and distributed from Coral servers automatically. Coral CDN does not support HTTPS and therefore secure pages will be served referencing local images.
The FTP/FTPS/SFTP integration utilizes the respective PHP wrapper. HTTPS delivery depends on the server and is configurable to work securely from the FTP server or the web server as determined in the configuration for the adapter.
At One Pica, we strive to build increasingly scalable and flexible enterprise systems for all of our clients, large and small. We want to give back to this community both to promote its success and as a sign of our gratitude. Please feel free to contact us on ways we can improve this extension or extend on this framework.