SlideShare a Scribd company logo
1 of 52
Download to read offline


🙇
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

More Related Content

What's hot

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
 

What's hot (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 to WordPress 運用を支える Perl

Perl web frameworks
Perl web frameworksPerl web frameworks
Perl web frameworksdiego_k
 
Curscatalyst
CurscatalystCurscatalyst
CurscatalystKar Juan
 
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 to WordPress 運用を支える Perl (20)

Perl web frameworks
Perl web frameworksPerl web frameworks
Perl web frameworks
 
Curscatalyst
CurscatalystCurscatalyst
Curscatalyst
 
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
 

More from 鉄次 尾形

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 位置情報とライフログ鉄次 尾形
 
設定ファイルに使われそうなデータ形式
設定ファイルに使われそうなデータ形式設定ファイルに使われそうなデータ形式
設定ファイルに使われそうなデータ形式鉄次 尾形
 

More from 鉄次 尾形 (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 位置情報とライフログ
 
設定ファイルに使われそうなデータ形式
設定ファイルに使われそうなデータ形式設定ファイルに使われそうなデータ形式
設定ファイルに使われそうなデータ形式
 

Recently uploaded

Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 

Recently uploaded (20)

Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 

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.