SlideShare una empresa de Scribd logo
1 de 52
Descargar para leer sin conexión


🙇
n


/wp-content/uploads/*
# aws s3 sync 
/var/www/sites/www.gaiax.co.jp/wp-content/uploads/ 
s3:// /wp-content/uploads/
#!/usr/bin/env perl
use strict;
use warnings;
use File::ChangeNotify;
my $watcher = File::ChangeNotify->instantiate_watcher(
directories => ["/var/www/sites/www.gaiax.co.jp/wp-content/uploads"],
);
while ( my @events = $watcher->wait_for_events() ) {
# TODO: aws s3 sync
system "aws", "s3", "sync", "--delete",
"/var/www/sites/www.gaiax.co.jp/wp-content/",
"s3://gxofficial-static/wp-content/";
}




PerlOutputFilterHandler
package ModPerl::WordPress::StaticURLRewriter;
# e.g.
# # in VirtualHost block directive
# <Files index.php>
# PerlOutputFilterHandler ModPerl::WordPress::StaticURLRewriter
# </Files>
#
use strict;
use warnings;
use base qw(Apache2::Filter);
use Apache2::Const -compile => qw(OK);
sub handler : FilterRequestHandler {
my $f = shift; # filter object
...
return Apache2::Const::OK;
}
1;
use constant BUFF_LEN => 1024;
sub handler : FilterRequestHandler {
my $f = shift;
unless ($f->ctx) {
$f->r->headers_out->unset('Content-Length');
$f->ctx(1);
}
my $content = '';
while ($f->read(my $buffer, BUFF_LEN)) {
$content .= $buffer;
}
### $content ###
$f->print($content);
if ( $f->seen_eos ) {
my $footer = "<!-- WRITE FOOTER IF EXIST -->";
$f->print($footer);
}
return Apache2::Const::OK;
}
$content
$content =~ s{(?<=<img)([^>]+)}{
my $in_img = $1;
$in_img =~ s{(?<=bsrc=(['"]))$PREFIX_SELF(.*?)(?=1)}{$PREFIX_S3$2};
$in_img;
}eg;
$content =~ s{(?<=<img)([^>]+)}{
$1 =~ s{(?<=bsrc=(['"]))$PREFIX_SELF(.*?)(?=1)}{$PREFIX_S3$2}r
}eg;


PerlMapToStorageHandler










package ModPerl::WordPress::CacheManager;
# e.g.
# # in VirtualHost block directive
# PerlMapToStorageHandler ModPerl::WordPress::CacheManager
use strict;
use warnings;
use Apache2::RequestRec ();
use Apache2::Const -compile => qw(OK DECLINED);
sub handler {
my $r = shift; # request object
# $r->uri() $filename
# $r->filename($filename)
...
return Apache2::Const::DECLINED;
}
1;
package ModPerl::WordPress::CacheManager;
use strict;
use warnings;
use Apache2::RequestRec ();
use Apache2::RequestUtil (); # for pnotes method
use Apache2::Const -compile => qw(OK DECLINED);
use APR::Table (); # for notes method
use File::Basename qw(dirname);
use File::Path qw(make_path);
use constant CACHE_LIFETIME => 3600;
sub handler {
my $r = shift;
if ( !is_cache_enable($r) ) {
return Apache2::Const::DECLINED;
}
manage_cache($r);
return Apache2::Const::DECLINED;
}
package ModPerl::WordPress::CacheManager;
# (snip)
sub is_cache_enable {
my $r = shift;
return $r->uri eq '/index.php'; # WordPress /index.php (entry-point)
}
sub manage_cache {
my $r = shift;
my $cache_filename = guess_cache_filename($r);
$r->notes->set( mpwp_cache_filename => $cache_filename );
if ( !-f $cache_filename
|| time - (stat _)[9] > CACHE_LIFETIME ) { # 9=mtime
$r->pnotes( mpwp_cache_generate_cb => &mpwp_cache_filename );
# ...
make_path(dirname($cache_filename));
} else {
$r->handler('default-handler');
$r->filename($cache_filename);
}
}
package ModPerl::WordPress::CacheManager;
# (snip)
sub mpwp_cache_filename {
my $f = shift;
my $contents_ref = shift; die if ref $contents_ref ne 'SCALAR';
my $filter_phase = !$f->ctx ? "INITIAL"
: $f->seen_eos ? "SEEN_EOS" : "IN_PROGRESS";
my $cache_filename = $f->r->notes->get("mpwp_cache_filename");
if ( $filter_phase eq "INITIAL" ) {
unlink $cache_filename; # remove old cache
}
if ( open my $fh, '>>', "$cache_filename.$$" ) {
print {$fh} $$contents_ref;
}
if ( $filter_phase eq "SEEN_EOS" ) {
rename "$cache_filename.$$" => $cache_filename;
}
}
aws s3
sync
aws s3
sync
🤝
aws s3
sync
🤝


http://www.gaiax.co.jp/blog/natalia03/
WordPress 運用を支える Perl
WordPress 運用を支える Perl
WordPress 運用を支える Perl

Más contenido relacionado

La actualidad más candente

KubeCon EU 2016: Custom Volume Plugins
KubeCon EU 2016: Custom Volume PluginsKubeCon EU 2016: Custom Volume Plugins
KubeCon EU 2016: Custom Volume PluginsKubeAcademy
 
Ansible leveraging 2.0
Ansible leveraging 2.0Ansible leveraging 2.0
Ansible leveraging 2.0bcoca
 
Docker tips & tricks
Docker  tips & tricksDocker  tips & tricks
Docker tips & tricksDharmit Shah
 
Hacking Mac OSX Cocoa API from Perl
Hacking Mac OSX Cocoa API from PerlHacking Mac OSX Cocoa API from Perl
Hacking Mac OSX Cocoa API from Perltypester
 
Shell Script to Extract IP Address, MAC Address Information
Shell Script to Extract IP Address, MAC Address InformationShell Script to Extract IP Address, MAC Address Information
Shell Script to Extract IP Address, MAC Address InformationVCP Muthukrishna
 
More tips n tricks
More tips n tricksMore tips n tricks
More tips n tricksbcoca
 
Configuration surgery with Augeas (OggCamp 12)
Configuration surgery with Augeas (OggCamp 12)Configuration surgery with Augeas (OggCamp 12)
Configuration surgery with Augeas (OggCamp 12)Dominic Cleal
 
とにかく始めるClojure
とにかく始めるClojureとにかく始めるClojure
とにかく始めるClojureMasayuki Muto
 
JDD 2017: Nginx + Lua = OpenResty (Marcin Stożek)
JDD 2017: Nginx + Lua = OpenResty (Marcin Stożek)JDD 2017: Nginx + Lua = OpenResty (Marcin Stożek)
JDD 2017: Nginx + Lua = OpenResty (Marcin Stożek)PROIDEA
 
Ansible tips & tricks
Ansible tips & tricksAnsible tips & tricks
Ansible tips & tricksbcoca
 
Codeigniter4の比較と検証
Codeigniter4の比較と検証Codeigniter4の比較と検証
Codeigniter4の比較と検証ME iBotch
 
Apache Hadoop for System Administrators
Apache Hadoop for System AdministratorsApache Hadoop for System Administrators
Apache Hadoop for System AdministratorsAllen Wittenauer
 
File Space Usage Information and EMail Report - Shell Script
File Space Usage Information and EMail Report - Shell ScriptFile Space Usage Information and EMail Report - Shell Script
File Space Usage Information and EMail Report - Shell ScriptVCP Muthukrishna
 
Powerful and flexible templates with Twig
Powerful and flexible templates with Twig Powerful and flexible templates with Twig
Powerful and flexible templates with Twig Michael Peacock
 
Bash Script Disk Space Utilization Report and EMail
Bash Script Disk Space Utilization Report and EMailBash Script Disk Space Utilization Report and EMail
Bash Script Disk Space Utilization Report and EMailVCP Muthukrishna
 
"Ops Tools with Perl" 2012/05/12 Hokkaido.pm
"Ops Tools with Perl" 2012/05/12 Hokkaido.pm"Ops Tools with Perl" 2012/05/12 Hokkaido.pm
"Ops Tools with Perl" 2012/05/12 Hokkaido.pmRyosuke IWANAGA
 
eZ Publish cluster unleashed revisited
eZ Publish cluster unleashed revisitedeZ Publish cluster unleashed revisited
eZ Publish cluster unleashed revisitedBertrand Dunogier
 
Nginx Workshop Aftermath
Nginx Workshop AftermathNginx Workshop Aftermath
Nginx Workshop AftermathDenis Zhdanov
 
Redis as a message queue
Redis as a message queueRedis as a message queue
Redis as a message queueBrandon Lamb
 

La actualidad más candente (20)

KubeCon EU 2016: Custom Volume Plugins
KubeCon EU 2016: Custom Volume PluginsKubeCon EU 2016: Custom Volume Plugins
KubeCon EU 2016: Custom Volume Plugins
 
Ansible leveraging 2.0
Ansible leveraging 2.0Ansible leveraging 2.0
Ansible leveraging 2.0
 
Docker tips & tricks
Docker  tips & tricksDocker  tips & tricks
Docker tips & tricks
 
Hacking Mac OSX Cocoa API from Perl
Hacking Mac OSX Cocoa API from PerlHacking Mac OSX Cocoa API from Perl
Hacking Mac OSX Cocoa API from Perl
 
Shell Script to Extract IP Address, MAC Address Information
Shell Script to Extract IP Address, MAC Address InformationShell Script to Extract IP Address, MAC Address Information
Shell Script to Extract IP Address, MAC Address Information
 
More tips n tricks
More tips n tricksMore tips n tricks
More tips n tricks
 
Configuration surgery with Augeas (OggCamp 12)
Configuration surgery with Augeas (OggCamp 12)Configuration surgery with Augeas (OggCamp 12)
Configuration surgery with Augeas (OggCamp 12)
 
とにかく始めるClojure
とにかく始めるClojureとにかく始めるClojure
とにかく始めるClojure
 
JDD 2017: Nginx + Lua = OpenResty (Marcin Stożek)
JDD 2017: Nginx + Lua = OpenResty (Marcin Stożek)JDD 2017: Nginx + Lua = OpenResty (Marcin Stożek)
JDD 2017: Nginx + Lua = OpenResty (Marcin Stożek)
 
Ansible tips & tricks
Ansible tips & tricksAnsible tips & tricks
Ansible tips & tricks
 
Codeigniter4の比較と検証
Codeigniter4の比較と検証Codeigniter4の比較と検証
Codeigniter4の比較と検証
 
Apache Hadoop for System Administrators
Apache Hadoop for System AdministratorsApache Hadoop for System Administrators
Apache Hadoop for System Administrators
 
Tutorial Puppet
Tutorial PuppetTutorial Puppet
Tutorial Puppet
 
File Space Usage Information and EMail Report - Shell Script
File Space Usage Information and EMail Report - Shell ScriptFile Space Usage Information and EMail Report - Shell Script
File Space Usage Information and EMail Report - Shell Script
 
Powerful and flexible templates with Twig
Powerful and flexible templates with Twig Powerful and flexible templates with Twig
Powerful and flexible templates with Twig
 
Bash Script Disk Space Utilization Report and EMail
Bash Script Disk Space Utilization Report and EMailBash Script Disk Space Utilization Report and EMail
Bash Script Disk Space Utilization Report and EMail
 
"Ops Tools with Perl" 2012/05/12 Hokkaido.pm
"Ops Tools with Perl" 2012/05/12 Hokkaido.pm"Ops Tools with Perl" 2012/05/12 Hokkaido.pm
"Ops Tools with Perl" 2012/05/12 Hokkaido.pm
 
eZ Publish cluster unleashed revisited
eZ Publish cluster unleashed revisitedeZ Publish cluster unleashed revisited
eZ Publish cluster unleashed revisited
 
Nginx Workshop Aftermath
Nginx Workshop AftermathNginx Workshop Aftermath
Nginx Workshop Aftermath
 
Redis as a message queue
Redis as a message queueRedis as a message queue
Redis as a message queue
 

Similar a WordPress 運用を支える Perl

Curscatalyst
CurscatalystCurscatalyst
CurscatalystKar Juan
 
Perl web frameworks
Perl web frameworksPerl web frameworks
Perl web frameworksdiego_k
 
Puppet for Java developers - JavaZone NO 2012
Puppet for Java developers - JavaZone NO 2012Puppet for Java developers - JavaZone NO 2012
Puppet for Java developers - JavaZone NO 2012Carlos Sanchez
 
Aura Project for PHP
Aura Project for PHPAura Project for PHP
Aura Project for PHPHari K T
 
Continuous Delivery with Maven, Puppet and Tomcat - ApacheCon NA 2013
Continuous Delivery with Maven, Puppet and Tomcat - ApacheCon NA 2013Continuous Delivery with Maven, Puppet and Tomcat - ApacheCon NA 2013
Continuous Delivery with Maven, Puppet and Tomcat - ApacheCon NA 2013Carlos Sanchez
 
Kansai.pm 10周年記念 Plack/PSGI 入門
Kansai.pm 10周年記念 Plack/PSGI 入門Kansai.pm 10周年記念 Plack/PSGI 入門
Kansai.pm 10周年記念 Plack/PSGI 入門lestrrat
 
Advanced symfony Techniques
Advanced symfony TechniquesAdvanced symfony Techniques
Advanced symfony TechniquesKris Wallsmith
 
Configuration Surgery with Augeas
Configuration Surgery with AugeasConfiguration Surgery with Augeas
Configuration Surgery with AugeasPuppet
 
Deploy Rails Application by Capistrano
Deploy Rails Application by CapistranoDeploy Rails Application by Capistrano
Deploy Rails Application by CapistranoTasawr Interactive
 
Quality Use Of Plugin
Quality Use Of PluginQuality Use Of Plugin
Quality Use Of PluginYasuo Harada
 
Puppet: What _not_ to do
Puppet: What _not_ to doPuppet: What _not_ to do
Puppet: What _not_ to doPuppet
 
PuppetCamp Ghent - What Not to Do with Puppet
PuppetCamp Ghent - What Not to Do with PuppetPuppetCamp Ghent - What Not to Do with Puppet
PuppetCamp Ghent - What Not to Do with PuppetWalter Heck
 
PuppetCamp Ghent - What Not to Do with Puppet
PuppetCamp Ghent - What Not to Do with PuppetPuppetCamp Ghent - What Not to Do with Puppet
PuppetCamp Ghent - What Not to Do with PuppetOlinData
 
Zendcon 2007 Api Design
Zendcon 2007 Api DesignZendcon 2007 Api Design
Zendcon 2007 Api Designunodelostrece
 
Writing and Publishing Puppet Modules - PuppetConf 2014
Writing and Publishing Puppet Modules - PuppetConf 2014Writing and Publishing Puppet Modules - PuppetConf 2014
Writing and Publishing Puppet Modules - PuppetConf 2014Puppet
 
Mastering the AWS SDK for PHP (TLS306) | AWS re:Invent 2013
Mastering the AWS SDK for PHP (TLS306) | AWS re:Invent 2013Mastering the AWS SDK for PHP (TLS306) | AWS re:Invent 2013
Mastering the AWS SDK for PHP (TLS306) | AWS re:Invent 2013Amazon Web Services
 
vfsStream - effective filesystem mocking
vfsStream - effective filesystem mocking vfsStream - effective filesystem mocking
vfsStream - effective filesystem mocking Sebastian Marek
 
Deploying Rails Applications with Capistrano
Deploying Rails Applications with CapistranoDeploying Rails Applications with Capistrano
Deploying Rails Applications with CapistranoAlmir Mendes
 

Similar a WordPress 運用を支える Perl (20)

Curscatalyst
CurscatalystCurscatalyst
Curscatalyst
 
Perl web frameworks
Perl web frameworksPerl web frameworks
Perl web frameworks
 
Puppet for Java developers - JavaZone NO 2012
Puppet for Java developers - JavaZone NO 2012Puppet for Java developers - JavaZone NO 2012
Puppet for Java developers - JavaZone NO 2012
 
Aura Project for PHP
Aura Project for PHPAura Project for PHP
Aura Project for PHP
 
Continuous Delivery with Maven, Puppet and Tomcat - ApacheCon NA 2013
Continuous Delivery with Maven, Puppet and Tomcat - ApacheCon NA 2013Continuous Delivery with Maven, Puppet and Tomcat - ApacheCon NA 2013
Continuous Delivery with Maven, Puppet and Tomcat - ApacheCon NA 2013
 
Kansai.pm 10周年記念 Plack/PSGI 入門
Kansai.pm 10周年記念 Plack/PSGI 入門Kansai.pm 10周年記念 Plack/PSGI 入門
Kansai.pm 10周年記念 Plack/PSGI 入門
 
Advanced symfony Techniques
Advanced symfony TechniquesAdvanced symfony Techniques
Advanced symfony Techniques
 
Configuration Surgery with Augeas
Configuration Surgery with AugeasConfiguration Surgery with Augeas
Configuration Surgery with Augeas
 
Augeas @RMLL 2012
Augeas @RMLL 2012Augeas @RMLL 2012
Augeas @RMLL 2012
 
Deploy Rails Application by Capistrano
Deploy Rails Application by CapistranoDeploy Rails Application by Capistrano
Deploy Rails Application by Capistrano
 
Quality Use Of Plugin
Quality Use Of PluginQuality Use Of Plugin
Quality Use Of Plugin
 
Puppet: What _not_ to do
Puppet: What _not_ to doPuppet: What _not_ to do
Puppet: What _not_ to do
 
PuppetCamp Ghent - What Not to Do with Puppet
PuppetCamp Ghent - What Not to Do with PuppetPuppetCamp Ghent - What Not to Do with Puppet
PuppetCamp Ghent - What Not to Do with Puppet
 
PuppetCamp Ghent - What Not to Do with Puppet
PuppetCamp Ghent - What Not to Do with PuppetPuppetCamp Ghent - What Not to Do with Puppet
PuppetCamp Ghent - What Not to Do with Puppet
 
Blog Hacks 2011
Blog Hacks 2011Blog Hacks 2011
Blog Hacks 2011
 
Zendcon 2007 Api Design
Zendcon 2007 Api DesignZendcon 2007 Api Design
Zendcon 2007 Api Design
 
Writing and Publishing Puppet Modules - PuppetConf 2014
Writing and Publishing Puppet Modules - PuppetConf 2014Writing and Publishing Puppet Modules - PuppetConf 2014
Writing and Publishing Puppet Modules - PuppetConf 2014
 
Mastering the AWS SDK for PHP (TLS306) | AWS re:Invent 2013
Mastering the AWS SDK for PHP (TLS306) | AWS re:Invent 2013Mastering the AWS SDK for PHP (TLS306) | AWS re:Invent 2013
Mastering the AWS SDK for PHP (TLS306) | AWS re:Invent 2013
 
vfsStream - effective filesystem mocking
vfsStream - effective filesystem mocking vfsStream - effective filesystem mocking
vfsStream - effective filesystem mocking
 
Deploying Rails Applications with Capistrano
Deploying Rails Applications with CapistranoDeploying Rails Applications with Capistrano
Deploying Rails Applications with Capistrano
 

Más de 鉄次 尾形

Perl入学式 2018年度の報告
Perl入学式 2018年度の報告Perl入学式 2018年度の報告
Perl入学式 2018年度の報告鉄次 尾形
 
【公開版】AWS基礎 for 新卒エンジニア
【公開版】AWS基礎 for 新卒エンジニア【公開版】AWS基礎 for 新卒エンジニア
【公開版】AWS基礎 for 新卒エンジニア鉄次 尾形
 
俺のこだわりデスクのその後
俺のこだわりデスクのその後俺のこだわりデスクのその後
俺のこだわりデスクのその後鉄次 尾形
 
障害対応とその防止策
障害対応とその防止策障害対応とその防止策
障害対応とその防止策鉄次 尾形
 
働きやすい社内を目指す!二酸化炭素計測ツール
働きやすい社内を目指す!二酸化炭素計測ツール働きやすい社内を目指す!二酸化炭素計測ツール
働きやすい社内を目指す!二酸化炭素計測ツール鉄次 尾形
 
Perl ウェブ開発の中世〜CGI と Plack の間〜
Perl ウェブ開発の中世〜CGI と Plack の間〜Perl ウェブ開発の中世〜CGI と Plack の間〜
Perl ウェブ開発の中世〜CGI と Plack の間〜鉄次 尾形
 
コードの動的生成のお話
コードの動的生成のお話コードの動的生成のお話
コードの動的生成のお話鉄次 尾形
 
三角関数の加法定理はなぜ難しいのか
三角関数の加法定理はなぜ難しいのか三角関数の加法定理はなぜ難しいのか
三角関数の加法定理はなぜ難しいのか鉄次 尾形
 
Perlで生きる10年
Perlで生きる10年Perlで生きる10年
Perlで生きる10年鉄次 尾形
 
穏やかにファイルを削除する続き
穏やかにファイルを削除する続き穏やかにファイルを削除する続き
穏やかにファイルを削除する続き鉄次 尾形
 
日本全国ぶらりPerl旅
日本全国ぶらりPerl旅日本全国ぶらりPerl旅
日本全国ぶらりPerl旅鉄次 尾形
 
穏やかにファイルを削除する
穏やかにファイルを削除する穏やかにファイルを削除する
穏やかにファイルを削除する鉄次 尾形
 
最近のメールまわりのお仕事のお話
最近のメールまわりのお仕事のお話最近のメールまわりのお仕事のお話
最近のメールまわりのお仕事のお話鉄次 尾形
 
再帰、漸化式、差分方程式とアルゴリズム Gx#20
再帰、漸化式、差分方程式とアルゴリズム   Gx#20再帰、漸化式、差分方程式とアルゴリズム   Gx#20
再帰、漸化式、差分方程式とアルゴリズム Gx#20鉄次 尾形
 
超小規模環境のMySQL #mysqlcasual
超小規模環境のMySQL #mysqlcasual超小規模環境のMySQL #mysqlcasual
超小規模環境のMySQL #mysqlcasual鉄次 尾形
 
mod_perlプログラマーがYAPCで語るレガシー開発論
mod_perlプログラマーがYAPCで語るレガシー開発論mod_perlプログラマーがYAPCで語るレガシー開発論
mod_perlプログラマーがYAPCで語るレガシー開発論鉄次 尾形
 
東京近郊のPerlコミュニティのご紹介 #lcs2015
東京近郊のPerlコミュニティのご紹介 #lcs2015東京近郊のPerlコミュニティのご紹介 #lcs2015
東京近郊のPerlコミュニティのご紹介 #lcs2015鉄次 尾形
 
4月16日だからFoursquare 位置情報とライフログ
4月16日だからFoursquare 位置情報とライフログ4月16日だからFoursquare 位置情報とライフログ
4月16日だからFoursquare 位置情報とライフログ鉄次 尾形
 
設定ファイルに使われそうなデータ形式
設定ファイルに使われそうなデータ形式設定ファイルに使われそうなデータ形式
設定ファイルに使われそうなデータ形式鉄次 尾形
 

Más de 鉄次 尾形 (20)

Perl入学式 2018年度の報告
Perl入学式 2018年度の報告Perl入学式 2018年度の報告
Perl入学式 2018年度の報告
 
【公開版】AWS基礎 for 新卒エンジニア
【公開版】AWS基礎 for 新卒エンジニア【公開版】AWS基礎 for 新卒エンジニア
【公開版】AWS基礎 for 新卒エンジニア
 
俺のこだわりデスクのその後
俺のこだわりデスクのその後俺のこだわりデスクのその後
俺のこだわりデスクのその後
 
Hokkaido.pmと7年
Hokkaido.pmと7年Hokkaido.pmと7年
Hokkaido.pmと7年
 
障害対応とその防止策
障害対応とその防止策障害対応とその防止策
障害対応とその防止策
 
働きやすい社内を目指す!二酸化炭素計測ツール
働きやすい社内を目指す!二酸化炭素計測ツール働きやすい社内を目指す!二酸化炭素計測ツール
働きやすい社内を目指す!二酸化炭素計測ツール
 
Perl ウェブ開発の中世〜CGI と Plack の間〜
Perl ウェブ開発の中世〜CGI と Plack の間〜Perl ウェブ開発の中世〜CGI と Plack の間〜
Perl ウェブ開発の中世〜CGI と Plack の間〜
 
コードの動的生成のお話
コードの動的生成のお話コードの動的生成のお話
コードの動的生成のお話
 
三角関数の加法定理はなぜ難しいのか
三角関数の加法定理はなぜ難しいのか三角関数の加法定理はなぜ難しいのか
三角関数の加法定理はなぜ難しいのか
 
Perlで生きる10年
Perlで生きる10年Perlで生きる10年
Perlで生きる10年
 
穏やかにファイルを削除する続き
穏やかにファイルを削除する続き穏やかにファイルを削除する続き
穏やかにファイルを削除する続き
 
日本全国ぶらりPerl旅
日本全国ぶらりPerl旅日本全国ぶらりPerl旅
日本全国ぶらりPerl旅
 
穏やかにファイルを削除する
穏やかにファイルを削除する穏やかにファイルを削除する
穏やかにファイルを削除する
 
最近のメールまわりのお仕事のお話
最近のメールまわりのお仕事のお話最近のメールまわりのお仕事のお話
最近のメールまわりのお仕事のお話
 
再帰、漸化式、差分方程式とアルゴリズム Gx#20
再帰、漸化式、差分方程式とアルゴリズム   Gx#20再帰、漸化式、差分方程式とアルゴリズム   Gx#20
再帰、漸化式、差分方程式とアルゴリズム Gx#20
 
超小規模環境のMySQL #mysqlcasual
超小規模環境のMySQL #mysqlcasual超小規模環境のMySQL #mysqlcasual
超小規模環境のMySQL #mysqlcasual
 
mod_perlプログラマーがYAPCで語るレガシー開発論
mod_perlプログラマーがYAPCで語るレガシー開発論mod_perlプログラマーがYAPCで語るレガシー開発論
mod_perlプログラマーがYAPCで語るレガシー開発論
 
東京近郊のPerlコミュニティのご紹介 #lcs2015
東京近郊のPerlコミュニティのご紹介 #lcs2015東京近郊のPerlコミュニティのご紹介 #lcs2015
東京近郊のPerlコミュニティのご紹介 #lcs2015
 
4月16日だからFoursquare 位置情報とライフログ
4月16日だからFoursquare 位置情報とライフログ4月16日だからFoursquare 位置情報とライフログ
4月16日だからFoursquare 位置情報とライフログ
 
設定ファイルに使われそうなデータ形式
設定ファイルに使われそうなデータ形式設定ファイルに使われそうなデータ形式
設定ファイルに使われそうなデータ形式
 

Último

Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024SynarionITSolutions
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 

Último (20)

Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 

WordPress 運用を支える Perl

  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11. 🙇
  • 12.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23. # aws s3 sync /var/www/sites/www.gaiax.co.jp/wp-content/uploads/ s3:// /wp-content/uploads/
  • 24. #!/usr/bin/env perl use strict; use warnings; use File::ChangeNotify; my $watcher = File::ChangeNotify->instantiate_watcher( directories => ["/var/www/sites/www.gaiax.co.jp/wp-content/uploads"], ); while ( my @events = $watcher->wait_for_events() ) { # TODO: aws s3 sync system "aws", "s3", "sync", "--delete", "/var/www/sites/www.gaiax.co.jp/wp-content/", "s3://gxofficial-static/wp-content/"; } 

  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 32. package ModPerl::WordPress::StaticURLRewriter; # e.g. # # in VirtualHost block directive # <Files index.php> # PerlOutputFilterHandler ModPerl::WordPress::StaticURLRewriter # </Files> # use strict; use warnings; use base qw(Apache2::Filter); use Apache2::Const -compile => qw(OK); sub handler : FilterRequestHandler { my $f = shift; # filter object ... return Apache2::Const::OK; } 1;
  • 33. use constant BUFF_LEN => 1024; sub handler : FilterRequestHandler { my $f = shift; unless ($f->ctx) { $f->r->headers_out->unset('Content-Length'); $f->ctx(1); } my $content = ''; while ($f->read(my $buffer, BUFF_LEN)) { $content .= $buffer; } ### $content ### $f->print($content); if ( $f->seen_eos ) { my $footer = "<!-- WRITE FOOTER IF EXIST -->"; $f->print($footer); } return Apache2::Const::OK; }
  • 34. $content $content =~ s{(?<=<img)([^>]+)}{ my $in_img = $1; $in_img =~ s{(?<=bsrc=(['"]))$PREFIX_SELF(.*?)(?=1)}{$PREFIX_S3$2}; $in_img; }eg; $content =~ s{(?<=<img)([^>]+)}{ $1 =~ s{(?<=bsrc=(['"]))$PREFIX_SELF(.*?)(?=1)}{$PREFIX_S3$2}r }eg; 

  • 35.
  • 38. package ModPerl::WordPress::CacheManager; # e.g. # # in VirtualHost block directive # PerlMapToStorageHandler ModPerl::WordPress::CacheManager use strict; use warnings; use Apache2::RequestRec (); use Apache2::Const -compile => qw(OK DECLINED); sub handler { my $r = shift; # request object # $r->uri() $filename # $r->filename($filename) ... return Apache2::Const::DECLINED; } 1;
  • 39. package ModPerl::WordPress::CacheManager; use strict; use warnings; use Apache2::RequestRec (); use Apache2::RequestUtil (); # for pnotes method use Apache2::Const -compile => qw(OK DECLINED); use APR::Table (); # for notes method use File::Basename qw(dirname); use File::Path qw(make_path); use constant CACHE_LIFETIME => 3600; sub handler { my $r = shift; if ( !is_cache_enable($r) ) { return Apache2::Const::DECLINED; } manage_cache($r); return Apache2::Const::DECLINED; }
  • 40. package ModPerl::WordPress::CacheManager; # (snip) sub is_cache_enable { my $r = shift; return $r->uri eq '/index.php'; # WordPress /index.php (entry-point) } sub manage_cache { my $r = shift; my $cache_filename = guess_cache_filename($r); $r->notes->set( mpwp_cache_filename => $cache_filename ); if ( !-f $cache_filename || time - (stat _)[9] > CACHE_LIFETIME ) { # 9=mtime $r->pnotes( mpwp_cache_generate_cb => &mpwp_cache_filename ); # ... make_path(dirname($cache_filename)); } else { $r->handler('default-handler'); $r->filename($cache_filename); } }
  • 41. package ModPerl::WordPress::CacheManager; # (snip) sub mpwp_cache_filename { my $f = shift; my $contents_ref = shift; die if ref $contents_ref ne 'SCALAR'; my $filter_phase = !$f->ctx ? "INITIAL" : $f->seen_eos ? "SEEN_EOS" : "IN_PROGRESS"; my $cache_filename = $f->r->notes->get("mpwp_cache_filename"); if ( $filter_phase eq "INITIAL" ) { unlink $cache_filename; # remove old cache } if ( open my $fh, '>>', "$cache_filename.$$" ) { print {$fh} $$contents_ref; } if ( $filter_phase eq "SEEN_EOS" ) { rename "$cache_filename.$$" => $cache_filename; } }
  • 45.
  • 46.
  • 47.
  • 48.