Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Laravel OctaneをどうしてもPharで運用したい話

Laravel OctaneをどうしてもPharで運用したい話

PHPerKaigi2022の発表資料です

--発表概要--

Laravel Octane(オクタン)は、SwooleやRoadRunnerなどの高性能なアプリケーションサーバを使用し、アプリケーションを提供することで、アプリケーションのパフォーマンスを向上させます。Octaneはアプリケーションを一度起動したら、メモリ内に保持し、そして超音速でリクエストを送り返します
(引用:https://readouble.com/laravel/8.x/ja/octane.html
Laravel Octane(Swoole版)でPharをつかってワンバイナリアプリケーションにして運用してみた話です
過去、PHPカンファレンス北海道(2019)にて
「pharによるワンバイナリアプリケーションの可能性を探ってみた」
でお話ししましたが、そのリベンジ(現実版)になります
PHPだけど、Buildして(Pharでpackして)、Deployして運用してみよう!

CyberAgent SGE Engineer

April 10, 2022
Tweet

More Decks by CyberAgent SGE Engineer

Other Decks in Programming

Transcript

  1. -BSBWFM0DUBOFΛ
    Ͳ͏ͯ͠΋
    1IBSͰӡ༻͍ͨ͠࿩
    גࣜձࣾαΠόʔΤʔδΣϯτɹനҪӳ

    QIQFSLBJHJ
    !HPPEPP

    View full-size slide

  2. • גࣜձࣾαΠόʔΤʔδΣϯτ
    • 4(&౷ׅຊ෦ٕज़౷ׅࣨࣨ௕
    • ࢠձࣾࣾ$50
    • גࣜձࣾ$SBGU&HH
    • גࣜձࣾαϜβοϓ
    • നҪɹӳ
    • ΤϯδχΞ
    • #MPH
    IUUQBNFCMPKQHPPEPP
    ͓લɺ୭Α
    • 5XJUUFS
    !HPPEPP
    • %2
    ࠷ߴͰͨ͠

    View full-size slide

  3. "HFOEB
    w-BSBWFM0DUBOFͱ͸ʁ
    wͲ͏ͯ͠΋1IBSͰʁ
    w-BSBWFM0DUBOF 4XPPMF
    ͷىಈॲཧΛݟΔ
    w1IBSԽʂ
    w࣮ࡍͷӡ༻࣌ͷߏ੒
    w·ͱΊ

    View full-size slide

  4. -BSBWFM0DUBOFͱ͸ʁ

    View full-size slide

  5. -BSBWFM0DUBOF
    -BSBWFM0DUBOFʢΦΫλϯʣ͸ɺ4XPPMF΍3PBE3VOOFSͳͲͷ
    ߴੑೳͳΞϓϦέʔγϣϯαʔόΛ࢖༻͠ɺΞϓϦέʔγϣϯΛఏ
    ڙ͢Δ͜ͱͰɺΞϓϦέʔγϣϯͷύϑΥʔϚϯεΛ޲্ͤ͞·
    ͢ɻ0DUBOF͸ΞϓϦέʔγϣϯΛҰ౓ىಈͨ͠ΒɺϝϞϦ಺ʹอ
    ࣋͠ɺͦͯ͠௒Ի଎ͰϦΫΤετΛૹΓฦ͠·͢ɻ
    ʢIUUQTSFBEPVCMFDPNMBSBWFMYKBPDUBOFIUNMʣ
    4XPPMFΛ1)1Ͱ΋ͬͱ΋ਓؾͷߴ͍
    ϑϨʔϜϫʔΫͷ-BSBWFM͕औΓࠐΜͩʂ

    View full-size slide

  6. 4XPPMFͱ͸ʁ
    4XPPMFJTBOFWFOUESJWFOBTZODISPOPVTDPSPVUJOFCBTFE
    DPODVSSFODZOFUXPSLJOHDPNNVOJDBUJPOFOHJOFXJUIIJHI
    QFSGPSNBODFXSJUUFOJO$GPS1)1
    IUUQTHJUIVCDPNTXPPMFTXPPMFTSD

    Πϕϯτۦಈܕͷඇಉظɾίϧʔνϯܕฒߦॲཧ
    ωοτϫʔΫ௨৴Τϯδϯ
    ඇಉظॲཧ΍ฒߦॲཧ͕͓खܰʹ͔͚Δʂ
    )551αʔόʔɺ8FC4PDLFUαʔόʔ͕Մೳʂ

    View full-size slide

  7. -BSBWFM0DUBOFΛ࢖͏͜ͱͰ
    1)1୯ମͰ
    )551αʔόʔʹ
    ͳΕΔʂ

    View full-size slide

  8. Ͳ͏ͯ͠΋1IBSͰʁ

    View full-size slide

  9. ಥવͰ͕࣭͢໰Ͱ͢

    View full-size slide

  10. 1IBSͳΜͯಡΈ·͔͢ʁ

    ͽʔ΁͍ͪ͑ʔ͋ʔΔ

    ͺʔ

    ;͊ʔ

    View full-size slide

  11. ࢲ͸
    ͷʮ;͊ʔʯͰ͢
    ;͊ʔ

    View full-size slide

  12. 1)1FS΋
    ϫϯόΠφϦͰ
    σϓϩΠ͍ͨ͠

    View full-size slide

  13. 1IBSͬͯԿʁ
    1IBSΞʔΧΠϒ͸ɺෳ਺ͷϑΝΠϧΛͻͱͭʹ
    ·ͱΊΔͨΊͷศརͳ࢓૊ΈͰ͢
    1IBSΞʔΧΠϒΛ࢖༻͢Ε͹ɺ1)1ͷΞϓϦ
    έʔγϣϯΛͻͱͭͷϑΝΠϧͱͯ͠഑෍Ͱ͖Δ
    Α͏ʹͳΓ·͢ɻ·ͨɺͦΕΛσΟεΫ্ʹల
    ։͠ͳͯ͘΋ͦͷ··࣮ߦͰ͖ΔͷͰ͢
    Ҿ༻ɿ1)1ϚχϡΞϧ
    IUUQTXXXQIQOFUNBOVBMKBJOUSPQIBSQIQ

    View full-size slide

  14. 1IBSΞʔΧΠϒΛ࢖༻͢Ε͹ɺ
    1)1ͷΞϓϦέʔγϣϯΛͻͱͭ
    ͷϑΝΠϧͱͯ͠഑෍Ͱ͖ΔΑ͏ʹ
    ͳΓ·͢
    ·ͨɺͦΕΛσΟεΫ্ʹల։͠ͳ
    ͯ͘΋ͦͷ··࣮ߦͰ͖ΔͷͰ͢

    View full-size slide

  15. ͦͷ··࣮ߦͰ͖Δ

    View full-size slide

  16. ͱ͍͏࿩Λɺ1)1ΧϯϑΝϨϯε๺ւಓͰ͠·ͨ͠
    https://speakerdeck.com/sgeengineer/pharniyoruwanbainariapurikesiyonfalseke-neng-xing-wotan-tutemita

    View full-size slide

  17. ͦͷ࣌΍Γ͖Εͳ͔ͬͨ఺

    View full-size slide

  18. Ϗϧυ͕࣌ؒ௕͍ɾɾ

    View full-size slide

  19. ͜Ε͡Ό࣮͋༻త͡Όͳ͍ʂ
    Ϧϕϯδʂ

    View full-size slide

  20. ͦ΋ͦ΋ͳͥϏϧυ࣌ؒ
    ͕௕͘ͳΔͷ͔ʁ

    View full-size slide

  21. $phar = new Phar('hoge.phar');
    $phar->addFromString('hoge.php', file_get_contents('./hoge.php'));
    $phar->setStub("Phar::mapPhar();\n
    require 'phar://hoge.phar/hoge.php'; \n
    __HALT_COMPILER();”);
    BEE'SPN4USJOH
    Λ࢖༻ͯ͠
    1IBS࡞੒͍ͯͨ͠

    View full-size slide

  22. 1IBSBEE'SPN4USJOH
    ͸ɺݺͼग़͞ΕΔ
    ͨͼʹ৽͍͠1IBSΞʔΧΠϒΛ࡞੒͠·͢ɻ
    https://www.php.net/manual/ja/phar.addfromstring.php
    ͑ʂ

    View full-size slide

  23. ϚχϡΞϧʹै͍ૉ௚ʹ
    CVJME'SPN%JSFDUPSZ

    Λ࢖͍·ͨ͠
    ΋͏Ұͭ঺հ͞Ε͍ͯΔCVJME'SPN*UFSBUPS
    ͸ɺ
    ϑΝΠϧ਺͕ଟ͍ͱϝϞϦʔ͕଍Βͳ͍Τϥʔ͕
    ͰΔͨΊஅ೦

    View full-size slide

  24. ઌʹϏϧυ࣌ؒͷ݁Ռ͚ͩ
    ඵͰϏϧυ׬ྃʂ
    ࣮༻తʹͳͬͨʂ

    View full-size slide

  25. ιʔε͸͜Μͳ͔Μ͡
    ΊͬͪΌγϯϓϧʂ

    View full-size slide

  26. ͜ΕͰউͭΔʂ
    ͦ͏ࢥͬͨ࣌ظ͕ࣗ෼ʹ
    ΋͋Γ·ͨ͠ɾɾ

    View full-size slide

  27. -BSBWFM0DUBOF 4XPPMF
    ͷ
    ىಈॲཧΛݟΔ

    View full-size slide

  28. QIQBSUJTBOPDUBOFTUBSUŠTFSWFSTXPPMF
    ىಈॲཧΛݟͯΈ·͢
    PDUBOFͷ4XPPMFͰͷىಈίϚϯυ͸࣍ͷΑ͏ʹͳΓ·͢
    ಺෦తʹ͸ɺ-BSBWFMa0DUBOFa$PNNBOETa4UBSU$PNNBOE͕ݺ͹Ε·͢
    ͦ͜Ͱ͞ΒʹɺUIJTDBMM bPDUBOFTXPPMF`
    ͕ίʔϧ͞Ε
    -BSBWFMa0DUBOFa$PNNBOETa4UBSU4XPPMF$PNNBOE͕ݺ͹Ε·͢

    View full-size slide

  29. 4UBSU4XPPMF$PNNBOEͷதΛݟΔͱ
    4ZNGPOZa$PNQPOFOUa1SPDFTTΛ͔ͭͬͯɺ
    zTXPPMFTFSWFSzͳΔ1)1εΫϦϓτΛىಈ͍ͤͯ͞Δʂ

    View full-size slide

  30. zTXPPMFTFSWFSzͷ1)1ϑΝΠϧ͸ɺ
    WFOEPSMBSBWFMPDUBOFCJOσΟϨΫτϦͷԼʹ͋Γ·͢

    View full-size slide

  31. zTXPPMFTFSWFSzͰPDUBOFͰTXPPMFΛىಈ͍ͤͯ͞Δ
    ࣮ॲཧ͕هड़͞Ε͍ͯΔͷͰ͕͢
    ຊ౰ʹૉͷ1)1εΫϦϓτϑΝΠϧͰ͢
    ϓϩηεΛݟΔͱBSUJTBOίϚϯυͰ͸ͳ͘ɺ
    TXPPMFTFSWFS͕ಈ͍͍ͯΔͷ͕֬ೝͰ͖·͢

    View full-size slide

  32. ͪͳΈʹ
    NBTUFS1SPDFTT
    NBOBHFS1SPDFTT
    XPSLFS1SPDFTT

    View full-size slide

  33. ͭ·ΓԿ͕ݴ͍͍͔ͨͱ͍͏ͱ
    1IBSϑΝΠϧͰΞϓϦͷىಈॲཧʹ͋ͨΔεΫϦϓτΛ
    BSUJTBOʹࢦఆ͍ͯ͠·͕ͨ͠
    ͜ΕͩͱTXPPMFTFSWFS͸ىಈͰ͖ͳ͍ʂ
    ͱ͍͏͜ͱͰ͢ʂ

    View full-size slide

  34. 1)1FS΋
    ϫϯόΠφϦͰ
    σϓϩΠ͍ͨ͠
    Ͱ͖ͳ͍ͷ͔ʂʁ

    View full-size slide

  35. ͦ͏ͩ
    πʔόΠφϦʔ
    ʹ͠Α͏ʂ

    View full-size slide

  36. πʔόΠφϦʔ
    1IBSϑΝΠϧͰΞϓϦͷىಈॲཧʹ͋ͨΔεΫϦϓτΛ
    TXPPMFTFSWFSΛࢦఆ͢Δ1IBSΛ࡞੒ʂ

    View full-size slide

  37. 4UBSU4XPPMF$PNNBOEಉ༷ͷॲཧΛ
    1IBSϑΝΠϧΛ࢖࣮ͬͯߦ͢Δ
    ىಈ$PNBNOEΛ࡞੒

    View full-size slide

  38. BSUJTBOίϚϯυ͔Β
    ઌ΄Ͳͷ
    $PNNBOE 1IBS4UBSU4XPPMF$PNNBOE

    Λ࣮ߦ͢Δʂ
    QIQBSUJTBOQIBSTXPPMFTUBSU
    ͜ΕͰ
    ͰɺTXPPMF4FSWFSQIBS͕ݺ΂Δɺͭ·Γ
    QIQBQQQIBSQIBSTXPPMFTUBSU
    BSUJTBOΛ1IBSͨ͠BQQQIBS͔ΒىಈͰ͖Δ

    View full-size slide

  39. 1IBSԽͰ͖ͨʂ

    View full-size slide

  40. ࣮ࡍͷӡ༻࣌ͷߏ੒

    View full-size slide

  41. ࠓճͷΞϓϦέʔγϣϯ͸࣮ࡍʹ
    (PPHMF$MPVEͷ$MPVE3VOͷ؀ڥͰ
    ӡ༻͍ͯ͠·͢

    View full-size slide

  42. ίϯςφલఏͷઃఆʹ͢Δඞཁ͕͋Γ·ͨ͠
    ͔ͭ
    1IBSΛ͔ͭ͏͜ͱʹΑΓඞཁͳઃఆ΋͋Γ·͢

    View full-size slide

  43. ίϯςφ޲͚ͷઃఆ
    ʢ̍ʣϩάͷઃఆ
    FOWͰඪ४Τϥʔग़ྗʹઃఆ͠·͢

    View full-size slide

  44. 1IBSͷͨΊͷઃఆ
    ʢʣPDUBOFTFSWFSTUBUFϑΝΠϧͷஔ͖৔ॴ
    TUPSBHFMPHT഑Լʹ
    PDUBOFTFSWFSTUBUFKTPOΛ࡞੒͠Α͏ͱ͠·͢
    VTF4UPSBHF1BUI
    Λ͔ͭͬͯUNQͳͲʹมߋ͠·͢
    ˞มߋλΠϛϯά͸CPPUTUSBQBQQQIQͰมߋ͠·͢

    View full-size slide

  45. %PDLFS'JMFͷத਎
    ɹɹɹɹશ෦ফͯ͠ɺ1IBSϑΝΠϧͷΈʹ͍ͯ͠·͢
    ˞FOWϑΝΠϧ͸1IBSϑΝΠϧʹ಺แ͓ͯ͠Γɺ಺แ͞ΕͨFOWͷ಺༰͕ࢀর͞Ε·͢

    View full-size slide

  46. ىಈॲཧ
    TVQFSWJTPSEDPOG

    View full-size slide

  47. 1IBSԽͰ͖ͨʂ

    View full-size slide

  48. w1IBSͷϏϧυʹ͔͔Δ࣌ؒΛ୹ॖͰ͖ͨ
    wCVJME'SPN%JSFDUPSZ
    ͷ࢖༻
    w-BSBWFM0DUBOF 4XPPMF
    Λ1IBSԽʂ
    w݁ՌπʔόΠφϦʔʹͳ͚ͬͨͲɾɾ
    w࣮ӡ༻Ͱӡ༻Ͱ͖͍ͯΔ
    w$MPVE3VOͰӡ༻த

    View full-size slide

  49. -FU`T1)1
    1SPHSBNNJOH

    View full-size slide

  50. ͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠

    View full-size slide