| 1 |
wimleers |
1.19 |
$Id$
|
| 2 |
wimleers |
1.6 |
|
| 3 |
|
|
Description
|
| 4 |
|
|
-----------
|
| 5 |
|
|
The aim of this module to provide easy Content Delivery Network integration
|
| 6 |
wimleers |
1.19 |
for Drupal sites. Obviously it has to patch Drupal core to rewrite the URLs.
|
| 7 |
|
|
URLs must be rewritten to be able to actually serve the files from a CDN.
|
| 8 |
wimleers |
1.6 |
|
| 9 |
wimleers |
1.19 |
It provides two modes: basic and advanced.
|
| 10 |
wimleers |
1.6 |
|
| 11 |
wimleers |
1.19 |
In basic mode, only "Origin Pull" CDNs are supported. These are CDNs that only
|
| 12 |
|
|
require you to replace the domain name (and possibly base path) with another
|
| 13 |
|
|
domain name. The CDN will then automatically fetch (pull) the files from your
|
| 14 |
|
|
server (the origin).
|
| 15 |
|
|
|
| 16 |
|
|
In advanced mode, you must install and configure the daemon I wrote as part of
|
| 17 |
|
|
my bachelor thesis. This allows for much more advanced setups: files can be
|
| 18 |
|
|
processed before they are synced and your CDN doesn't *have* to support
|
| 19 |
|
|
Origin Pull, any push method is fine. Push always uses transfer protocols,
|
| 20 |
|
|
either well-established ones (e.g. FTP) or custom ones (e.g. Amazon S3). It is
|
| 21 |
|
|
thanks to this abstraction layer that it can be used for *any* CDN, thereby
|
| 22 |
|
|
avoiding vendor lock-in.
|
| 23 |
|
|
|
| 24 |
|
|
This module was written as part of the bachelor thesis [1] of Wim Leers at
|
| 25 |
|
|
Hasselt University [3].
|
| 26 |
|
|
|
| 27 |
|
|
[1] http://wimleers.com/tags/bachelor-thesis
|
| 28 |
|
|
[2] http://uhasselt.be/
|
| 29 |
|
|
|
| 30 |
|
|
|
| 31 |
|
|
Supported CDNs
|
| 32 |
|
|
--------------
|
| 33 |
|
|
- Basic mode: any Origin Pull CDN.
|
| 34 |
|
|
- Advanced mode: any Origin Pull CDN and any push CDN that supports FTP.
|
| 35 |
|
|
Support for other transfer protocols is welcomed and encouraged: your
|
| 36 |
|
|
patches are welcome! Amazon S3 and Amazon CloudFront are also supported.
|
| 37 |
wimleers |
1.7 |
|
| 38 |
|
|
|
| 39 |
wimleers |
1.6 |
Installation
|
| 40 |
|
|
------------
|
| 41 |
wimleers |
1.19 |
1) Apply the Drupal core patch (patches/drupal6.patch). Instructions can be
|
| 42 |
|
|
found at http://drupal.org/patch/apply.
|
| 43 |
wimleers |
1.6 |
|
| 44 |
wimleers |
1.19 |
2) Place this module directory in your "modules" folder (this will usually be
|
| 45 |
|
|
"sites/all/modules/"). Don't install your module in Drupal core's "modules"
|
| 46 |
|
|
folder, since that will cause problems and is bad practice in general. If
|
| 47 |
|
|
"sites/all/modules" doesn't exist yet, just create it.
|
| 48 |
|
|
|
| 49 |
|
|
3) Enable the module.
|
| 50 |
|
|
|
| 51 |
|
|
4) Visit "admin/settings/cdn" to learn about the various settings.
|
| 52 |
|
|
|
| 53 |
|
|
5) If you want to use advanced mode, install and configure the daemon first.
|
| 54 |
|
|
You can install it by performing an svn checkout from
|
| 55 |
|
|
svn://wimleers.com/school/bachelor-thesis/code/daemon
|
| 56 |
|
|
Then follow the instructions in the included INSTALL.txt and README.txt.
|
| 57 |
|
|
Use the config.xml file that is included in this module and modify it to
|
| 58 |
|
|
comply with your setup and to suit your needs.
|
| 59 |
|
|
|
| 60 |
|
|
6) Go to admin/reports/status. The CDN integration module will report its
|
| 61 |
|
|
status here. If you've enabled advanced mode and have set up the daemon,
|
| 62 |
|
|
you will see some basic stats here as well, and you can check here to see
|
| 63 |
|
|
if the daemon is currently running.
|
| 64 |
|
|
|
| 65 |
|
|
|
| 66 |
|
|
When using multiple servers: picking a specific one based on some criteria
|
| 67 |
|
|
--------------------------------------------------------------------------
|
| 68 |
|
|
For this purpose, you can implement the cdn_advanced_pick_server() function:
|
| 69 |
|
|
/**
|
| 70 |
|
|
* Implementation of cdn_advanced_pick_server().
|
| 71 |
|
|
*/
|
| 72 |
|
|
function cdn_advanced_pick_server($servers_for_file) {
|
| 73 |
|
|
// The data that you get - one nested array per server from which the file
|
| 74 |
|
|
// can be served:
|
| 75 |
|
|
// $servers_for_file[0] = array('url' => 'http://cdn1.com/image.jpg', 'server' => 'cdn1.com')
|
| 76 |
|
|
// $servers_for_file[1] = array('url' => 'http://cdn2.net/image.jpg', 'server' => 'cdn2.net')
|
| 77 |
|
|
|
| 78 |
|
|
$which = your_logic_to_pick_a_server();
|
| 79 |
|
|
|
| 80 |
|
|
// Return one of the nested arrays.
|
| 81 |
|
|
return $servers_for_file[$which];
|
| 82 |
|
|
}
|
| 83 |
|
|
|
| 84 |
|
|
So to get the default behavior (pick the first server found), one would write:
|
| 85 |
|
|
/**
|
| 86 |
|
|
* Implementation of cdn_advanced_pick_server().
|
| 87 |
|
|
*/
|
| 88 |
|
|
function cdn_advanced_pick_server($servers_for_file) {
|
| 89 |
|
|
return $servers_for_file[0];
|
| 90 |
|
|
}
|
| 91 |
|
|
|
| 92 |
|
|
|
| 93 |
|
|
Supporting the CDN integration module in your modules
|
| 94 |
|
|
-----------------------------------------------------
|
| 95 |
|
|
It's very easy to support the CDN integration module in your module. Simply
|
| 96 |
|
|
create a variable function, e.g.:
|
| 97 |
|
|
$file_create_url = (module_exists('cdn')) ? 'file_create_url' : 'url';
|
| 98 |
wimleers |
1.6 |
|
| 99 |
wimleers |
1.19 |
Then create all file URLs using this variable function. E.g.
|
| 100 |
|
|
$file_url = $file_create_url(drupal_get_path('module', 'episodes') .'/lib/episodes.js');
|
| 101 |
wimleers |
1.6 |
|
| 102 |
|
|
|
| 103 |
|
|
Author
|
| 104 |
|
|
------
|
| 105 |
wimleers |
1.19 |
Wim Leers ~ http://wimleers.com/
|
| 106 |
wimleers |
1.6 |
|
| 107 |
wimleers |
1.19 |
This module was written as part of the bachelor thesis of Wim Leers at
|
| 108 |
|
|
Hasselt University.
|