Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
可能な限り確実にmkdirを成功させるには / Make mkdir
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Yuichi Sugiyama
PRO
March 25, 2023
Technology
780
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
可能な限り確実にmkdirを成功させるには / Make mkdir
PHPerKaigi 2023 のLTの資料です
Yuichi Sugiyama
PRO
March 25, 2023
More Decks by Yuichi Sugiyama
See All by Yuichi Sugiyama
20年以上続く PHP 大規模プロダクトを Kubernetes へ ── クラウド基盤刷新プロジェクトの4年間
oogfranz
PRO
0
570
サイボウズ と Garoon と The PHP Foundation と 私 / Cybozu and Garoon and The PHP Foundation and me
oogfranz
PRO
1
650
サイボウズ #Garoon 開発チームの 「 完成度低いの歓迎LT大会 」 PHPerKaigi出張版 / Low quality LT in PHPerKaigi 2023
oogfranz
PRO
0
800
20年ものの巨大プロダクトをKubernetesに移行している話 後日談/Garoon on Kubernetes after talk
oogfranz
PRO
0
670
20年ものの巨大プロダクトをKubernetesに移行している話/Garoon on Kubernetes
oogfranz
PRO
0
590
PHPアプリケーションだってモニタリングしたい / Monitoring PHP application
oogfranz
PRO
1
700
効果的な静的解析の CI導入パターンを求めて / Great static analysis with CI
oogfranz
PRO
3
4.1k
Dev-meets-Ops
oogfranz
PRO
1
1.1k
GitHub力の低い僕でも、 OSSコントリビュートできたワケ / GitHub Power
oogfranz
PRO
1
680
Other Decks in Technology
See All in Technology
なぜ東京にいる私が、新潟の技術コミュニティを運営するのか by 八雲慎之助
yakumo
0
150
データマネジメント × 法務で作りあげる、 freeeの新しいデータガバナンスへの軌跡
freee
PRO
2
580
Vibe-to-Spec開発_実践ガイド
happysamurai294
0
130
スマートロックを支えるFlutter × ネイティブ連携の実践 / Flutter and Native Integration in Practice: Powering Smart Locks
bitkey
PRO
0
110
"AWSはちょっと苦手"でも大丈夫。AWS Blocks で手軽に作る Flutter のバックエンド #FlutterKaigi
tacck
PRO
0
110
構造で守らせる データ・法務・セキュリティ・開発チームとつくる AI時代のデータガバナンスとデータ基盤のリアル
legalontechnologies
PRO
2
690
AI Search (Foundry IQ) におけるRAGデータの準備と配置
ryomaru0825
1
100
基本から分かる!AWSセキュリティ運用の考え方と任せ方
cmusudakeisuke
1
260
[FECONF-2026] 신대륙을 향한 카카오페이증권 프론트엔드 항해기 (이주승)
l1ghthouse
0
330
2拠点SRE活動始めてみた | sogaoh's LT @ ホンマでっかSRE勉強会 #3
sogaoh
PRO
0
210
契約で守るコンパウンドプロダクトのデザインシステム
yug1224
1
1.6k
Patterns in AI Driven Software Development
akosma
PRO
0
380
Featured
See All Featured
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
35
3.9k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
230
23k
Introduction to Domain-Driven Design and Collaborative software design
baasie
1
1.1k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
38
3.1k
Visual Storytelling: How to be a Superhuman Communicator
reverentgeek
2
730
So, you think you're a good person
axbom
PRO
2
2.2k
What’s in a name? Adding method to the madness
productmarketing
PRO
24
4.2k
Balancing Empowerment & Direction
lara
6
1.3k
Fantastic passwords and where to find them - at NoRuKo
philnash
53
4k
Collaborative Software Design: How to facilitate domain modelling decisions
baasie
1
360
Breaking role norms: Why Content Design is so much more than writing copy - Taylor Woolridge
uxyall
1
470
Navigating the Design Leadership Dip - Product Design Week Design Leaders+ Conference 2024
apolaine
2
490
Transcript
ՄೳͳݶΓ࣮֬ʹ mkdirΛޭͤ͞Δʹ PHPerKaigi 2023 ͗͢·@MASHݭָஂ
Whoami • ਿࢁ ༞Ұ @oogFranz • αΠϘζͰେاۀ͚άϧʔϓΣΞ Garoon (Ψϧʔϯ)
࡞ͬͯΔ • ෳۀϛϡʔδγϟϯ • MASHݭָஂɺFried Banana CabinɺϒϧʔάϥεˑϙϦε
σΟϨΫτϦΛPHP͔Β࡞Ε·͔͢ʁ function makeDirectory(string $path): bool { //??? }
mkdir() Ͱ༨༟ͩͥʂ function makeDirectory(string $path): bool { return mkdir($path); }
mkdir() Ͱ༨༟ͩͥʂ ͜ͷ࣮ͷΛग़དྷΔݶΓ্͛ͯΈ·͠ΐ͏ʂ function makeDirectory(string $path): bool { return mkdir($path);
}
σΟϨΫτϦύεΛࢦఆ͢ΔͱWarning makeDirectory('test/foo/bar'); //Warning: mkdir(): No such file or directory in
/usr/ local/code/mkdir.php on line 9 • testσΟϨΫτϦɺfoo σΟϨΫτϦ͕ଘࡏ͠ͳ͍߹ Warning͕ൃੜ͢Δ • σΟϨΫτϦ࡞͞Εͳ͍
ϚχϡΞϧΛͪΌΜͱಡΉ • recursiveΦϓγϣϯmkdir ͷ —parents, -p Φϓγϣϯͱಉ͡ • σΟϨΫτϦΛඞཁʹԠͯ͡࡞ͯ͘͠ΕΔ mkdir(
string $directory, int $permissions = 0777, bool $recursive = false, ?resource $context = null ): bool
recursive = trueΛ͏ function makeDirectory(string $path): bool { return mkdir($path,
recursive: true); }
σΟϨΫτϦ͕طʹଘࡏ͢ΔͱWarning • ࡞લʹis_dir(), fi le_exists()ͰνΣοΫ͕ඞཁ • ͜ΕϚχϡΞϧʹॻ͍ͯ͋Δ makeDirectory('foo'); makeDirectory('foo'); //
Warning: mkdir(): File exists in /usr/local/ code/mkdir.php on line 9
is_dir, fi le_existsΛ͏ function makeDirectory(string $path): bool { if (is_dir($path))
{ return true; } if (file_exists($path)) { return false; } return mkdir($path, recursive: true); } ✴ fi le_exists() ͕ trueͷͱ͖݁ՌతʹσΟϨΫτϦ͕࡞Ͱ͖ͳ͍ͷͰҙ
σΟϨΫτϦ͕ͳ͍ͷʹis_dir͕trueΛฦ͢ makeDirectory('foo/bar'); makeDirectory('foo/bar'); sleep(10); //͜͜Ͱผϓϩηε͔Βfoo/barσΟϨΫτϦΛআ͢Δ makeDirectory('foo/bar');
σΟϨΫτϦ͕ͳ͍ͷʹis_dir͕trueΛฦ͢ makeDirectory('foo/bar'); makeDirectory('foo/bar'); sleep(10); //͜͜Ͱผϓϩηε͔Βfoo/barσΟϨΫτϦΛআ͢Δ makeDirectory('foo/bar'); σΟϨΫτϦ͕࡞͞Εͳ͍ʂ
is_dir()Ωϟογϡ͞Ε͍ͯΔʂ • is_dir()ͳͲͷ݁ՌύϑΥʔϚϯεͷͨΊʹΩϟογϡ͞ΕΔ • Ωϟογϡϓϩηε͝ͱʹ࡞͞ΕΔɻ • ଞͷϓϩηεʹΑͬͯϑΝΠϧͷεςʔλε͕มΘΔ߹ ΩϟογϡͷΫϦΞ͕ඞཁ
clearstatcache()Λ͏ function makeDirectory(string $path): bool { clearstatcache(); if (is_dir($path)) {
return true; } if (file_exists($path)) { return false; } return mkdir($path, recursive: true); }
clearstatcache()Λ͏ function makeDirectory(string $path): bool { clearstatcache(); if (is_dir($path)) {
return true; } if (file_exists($path)) { return false; } return mkdir($path, recursive: true); } JT@EJS͕ਖ਼͘͠ಈ࡞͢Δ
࣮ߦλΠϛϯάʹΑͬͯWarning is_dir() is_dir() fi le_exits() fi le_exits() ϓϩηε1 ϓϩηε2 ·ͩσΟϨΫτϦ͕
ଘࡏ͠ͳ͍ͷͰGBMTF
࣮ߦλΠϛϯάʹΑͬͯWarning is_dir() is_dir() fi le_exits() fi le_exits() mkdir() ϓϩηε1 ϓϩηε2
σΟϨΫτϦ࡞ޭ
࣮ߦλΠϛϯάʹΑͬͯWarning is_dir() is_dir() fi le_exits() fi le_exits() mkdir() mkdir() ϓϩηε1
ϓϩηε2 σΟϨΫτϦ࡞ࣦഊʂ
Τϥʔͷ͑ํ • Τϥʔ੍ޚԋࢉࢠ `@` Λ͏ खܰɻͳΜ͔ෛ͚ͨؾ͕͢Δɻ • error_reporting Ͱ
E_WARNINGΛ͑Δ ଞͷE_WARNING͑ͯ͠·͏ͷͰ͓קΊ͠ͳ͍ • set_error_handler ͰWarningΛΩϟον͢Δ ਅ໘ʹΔͳΒ͜Εɻ • ഉଞ੍ޚʁʁ ΦʔόʔΩϧͰʁ͜ͷϝιουҎ֎͔Βͷݺͼग़͠ʹউͯͳ͍ɺɺɺ
Τϥʔ੍ޚԋࢉࢠΛͬͨ߹ function makeDirectory(string $path): bool { if (@mkdir($path, recursive: true)
=== false) { clearstatcache(); return is_dir($path); } return true; } • Τϥʔ੍ޚʹͤͯࣄલͷσΟϨΫτϦνΣοΫෆཁʢ͔ʣ
Permission • ͦͦ࡞ݖݶ͕ͳ͍߹E_WARNING͕ൃੜ • is_writableͰ֬ೝՄೳ • σΟϨΫτϦ͕͋Δͱ͖ɺͳ͍ͱ͖͕͋ΔͷͰ࠶ؼ͕ඞཁ • ͏࣮ߦ࣮ͯ͠ߦͰ͖Δ͔ࢼͨ͠ํ͕ૣ͘ͳ͍ʁʁ
→Τϥʔ੍ޚඞਢ
·ͱΊ • mkdirͳͲϑΝΠϧγεςϜʹ৮Δ߹ߟྀϙΠϯτଟ͍ • ϚχϡΞϧͪΌΜͱಡ͏ • ϑΝΠϧγεςϜͷΩϟογϡϋϚΔͱͭΒ͍ͷͰɺ clearstatcacheΛ͍·͠ΐ͏ •
ύʔϛογϣϯΉ͔͍ͣ͠ • Ͳ͏ؤுͬͯWarningಀΕΒΕͳ͍ͷͰɺ Τϥʔ੍ޚ͕ΜΓ·͠ΐ͏
αΠϘζPHPerKaigi ޙஊΠϕϯτʂ https://cybozu.connpass.com/event/277790/ 4/5ʢਫʣ 19:00~ @αΠϘζຊڮΦϑΟε