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
Yuichi Sugiyama
PRO
March 25, 2023
Technology
790
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
Transcript
23 slides
ՄೳͳݶΓ࣮֬ʹ 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~ @αΠϘζຊڮΦϑΟε
More Decks by Yuichi Sugiyama
See All by Yuichi Sugiyama
20年以上続く PHP 大規模プロダクトを Kubernetes へ ── クラウド基盤刷新プロジェクトの4年間
oogfranz
PRO
0
600
サイボウズ と Garoon と The PHP Foundation と 私 / Cybozu and Garoon and The PHP Foundation and me
oogfranz
PRO
1
660
サイボウズ #Garoon 開発チームの 「 完成度低いの歓迎LT大会 」 PHPerKaigi出張版 / Low quality LT in PHPerKaigi 2023
oogfranz
PRO
0
810
20年ものの巨大プロダクトをKubernetesに移行している話 後日談/Garoon on Kubernetes after talk
oogfranz
PRO
0
670
20年ものの巨大プロダクトをKubernetesに移行している話/Garoon on Kubernetes
oogfranz
PRO
0
600
PHPアプリケーションだってモニタリングしたい / Monitoring PHP application
oogfranz
PRO
1
700
効果的な静的解析の CI導入パターンを求めて / Great static analysis with CI
oogfranz
PRO
3
4.2k
Dev-meets-Ops
oogfranz
PRO
1
1.1k
GitHub力の低い僕でも、 OSSコントリビュートできたワケ / GitHub Power
oogfranz
PRO
1
690
Other Decks in Technology
See All in Technology
閉域網でのAPI公開の選択肢全部比較!
takano0131
5
700
ワークフローからハーネスへ — Web フレームワークの作者たちが AI エージェントに向かう理由
azukiazusa1
2
1.1k
新規事業開発でのAWS活用成功談&失敗談! 〜新規事業開発を専門に行うRelicならではのAWS活用〜
amixedcolor
1
140
セキュリティチームは どのコンテナイメージの脆弱性対応を優先すべきか 〜CISA新指針とSCCで作る脆弱性トリアージ〜
swdtkuy
0
330
みん強Lightning! データ基盤ひとりでできるかな
endonanana
0
200
Amazon EFS のマルウェアスキャンをClamAV で自前実装したら苦労した話
mtmtfactory01
0
110
ノードが消える前提で設計する!Karpenterで金融システムを止めないためのノウハウ大全
daitak
1
250
市販IoT機器や自作IoT機器とHomeAssistantを駆使して家の電気代をできる限り見える化する方法の考案
harutiro
0
420
「正しいデータ」の定義をAI エージェントとつくるGoogleADKによるデータ品質定義の実践
takaha4k
0
140
成長するID管理基盤における運用もコストも犠牲にしないオブザーバビリティ向上の実践 / Improving Observability for a Growing Identity Platform Without Adding Operational Burden or Cost
kaminashi
1
130
Well, that’s weird…
csswizardry
1
210
OCI Artifact による自動運転タクシーに向けた OTA 基盤の構築
biwashi
1
300
Featured
See All Featured
Data-driven link building: lessons from a $708K investment (BrightonSEO talk)
szymonslowik
1
1.5k
Jess Joyce - The Pitfalls of Following Frameworks
techseoconnect
PRO
1
480
16th Malabo Montpellier Forum Presentation
akademiya2063
PRO
0
470
Build The Right Thing And Hit Your Dates
maggiecrowley
39
3.5k
Practical Orchestrator
shlominoach
192
12k
Discover your Explorer Soul
emna__ayadi
2
1.3k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
56
3.5k
Exploring anti-patterns in Rails
aemeredith
4
580
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
28
3.8k
How STYLIGHT went responsive
nonsquared
100
6.4k
Code Reviewing Like a Champion
maltzj
529
40k
Leveraging LLMs for student feedback in introductory data science courses - posit::conf(2025)
minecr
1
490