Hi,
Is there any way to easily configure use of a CDN for Piwigo on a subdomain? Perhaps it would be a good idea for a plugin. I think serving images through a cdn would be very helpful to lessen the bandwidth used through the server and would speed up load times, especially for visitors far from the server. For example, images could be served from cdn.domain.com instead of from www.domain.com.
Offline
doesn't cdn generally used for common content ?(such as jquery)
i don't see how a single plugin could be compatible with all cdn systems.
do you know cloudflare ?
Offline
I have used Cloudflare and CDN77 on other non-Piwigo sites, but I am not an expert. A CDN is useful for any static content. This includes css/js/jquery, images, videos, pdf, doc, zip, etc. It depends on the CDN service what they allow. Some do now allow videos, for example.
I believe the idea would be for the admin to set the cdn domain in the plugin, such as cdn.domain.com, so all images will be served from cdn.domain.com. Then in the server hosting account, the admin must set the CNAME record for cdn.domain.com to the CNAME given by the CDN service such as cloudflare.
Setting the CNAME record is easy for users who host their own Piwigo, but I'm not sure how it will work for galleries hosted on Piwigo servers.
Offline
I'm already using a cdn here is my code
define('RVCDN', 'http://mycname.domain.com'); define('RVCDN_ROOT_URL', RVCDN . get_absolute_root_url(false)); add_event_handler('get_derivative_url', 'cdn_derivative_url', EVENT_HANDLER_PRIORITY_NEUTRAL, 4); add_event_handler('get_combined_css', 'cdn_combined_css', EVENT_HANDLER_PRIORITY_NEUTRAL, 2); add_event_handler('combined_script', 'cdn_combined_script', EVENT_HANDLER_PRIORITY_NEUTRAL, 2); add_event_handler('combined_css_postfilter', 'cdn_combined_css_postfilter'); function cdn_derivative_url($url, $params, $src, $rel_url) { if (strpos($url, '?')===false && ($params->type==IMG_THUMB || $params->type==IMG_XXSMALL) ) { $id = $src->id; if ($id%10==0 || $id%10==2) { if ($url[0]=='/') $url = RVCDN.$url; else $url = RVCDN_ROOT_URL.$rel_url; } } return $url; } function cdn_prefilter($source, &$smarty) { $source = str_replace('src="{$ROOT_URL}{$themeconf.icon_dir}/', 'src="'.RVCDN_ROOT_URL.'{$themeconf.icon_dir}/', $source); $source = str_replace('url({$'.'ROOT_URL}', 'url('.RVCDN_ROOT_URL, $source); return $source; } function cdn_combined_script($url, $script) { if (!$script->is_remote()) $url = RVCDN_ROOT_URL.$script->path; return $url; } function cdn_combined_css($url, $loc) { $url = RVCDN_ROOT_URL.$loc; return $url; } function cdn_combined_css_postfilter($css) { return str_replace('url(/', 'url('.RVCDN.'/', $css); }
Offline
That is awesome, though I'm not sure how to utilize that properly. Would I be able to paste it into the personal plugin section of localfiles editor? Would you be able to create a new plugin with that? I'm sure there are others that would be interested in using a CDN for their big galleries. Thanks
Offline
rvelices, is the cdn currently running on your gallery? I see all the images are served from your www subdomain not a cdn. Perhaps I do not understand how it works.
Offline
ViPeR_930 wrote:
rvelices, is the cdn currently running on your gallery? I see all the images are served from your www subdomain not a cdn. Perhaps I do not understand how it works.
check with firebug
http://a.modusoptimus.com/pwg/themes/de … ffffff.png for ex
This script use the CDn only for combined css and js and images of themes
Offline
Ah I see.
I went ahead and just setup with cloudflarecby changing nameservers. I didnt realize a cdn could be done easily without using an additional subdomain, but I think a separate subdomain is still helpful as a cookie free domain.
Offline
Hello,
This sounds great.
I would find it very useful for video self-hosting, and so, would you mind explaining where to put this code?
Or better : has anyone ever thought of creating a cdn plugin?
Offline
Hello,
I do agree with the idea.
I am looking for something similar.
Iwill probably work on a plugin to do so.
So far the hard part is to rewrite the URL to use the CDN URL and not the Origin URL.
I did not figure how to do so yet.
The code from rvelices might be a good starting point.
I wish to be able to select multiple subdomain by specific extensions.
For example *.jpg use cdn1.mydomain.com and *.png use cdn2.mydomain.com and *.mp4 use cdn3.mydomain.com
Offline
nec wrote:
Or better : has anyone ever thought of creating a cdn plugin?
Nope - use Cloudflare as a free CDN :)
Offline
I release a first version of a CDN plugin.
http://piwigo.org/ext/extension_view.php?eid=788
You can select multiple subdomain by specific extensions.
For example *.jpg use cdn1.mydomain.com and *.png use cdn2.mydomain.com and *.mp4 use cdn3.mydomain.com
I will include support for the CSS and JS of PWG in the next release.
Offline
Hi,
I'm going to test your plugin in a minute. Thank you very much for sharing it.
Congratulations.
Offline
Hi all,
Thanks for the feedback and all the translation help, http://piwigo.org/translate/project.php?project=cdnplus
Just release a new version 2.7.b that include the theme support and few other improvement.
https://github.com/xbgmsharp/piwigo-cdnplus/releases
You can select multiple subdomain by specific extensions.
For example *.jpg use cdn1.mydomain.com and *.png use cdn2.mydomain.com and *.mp4 use cdn3.mydomain.com
You can also have select one host for the themes file e.g.: css and js.
Enjoy, http://piwigo.org/ext/extension_view.php?eid=788
Offline
Instead of manually deciding what goes to a CNAME pointing to a CDN, I'd rather use something more like this:
https://wordpress.org/plugins/cloudflare/
This uses the cloud flare API to allow wordpress to 'know' the original IP (otherwise the piwigo app sees the cloud flare source, and all those neat statistics built in become meaningless).
The wordpress plugin is GPLv2 and source is viewable here:
http://plugins.svn.wordpress.org/cloudflare/trunk/
I don't yet know enough about piwigo's plugins to attempt this. I need to do some reading and/or find a "hello world" walkthrough for piwigo plugin development.
-Josh