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

pharによるワンバイナリアプリケーションの可能性を探ってみた

 pharによるワンバイナリアプリケーションの可能性を探ってみた

PHPカンファレンス北海道2019 LT発表資料

SwooleのフレームワークSwoftにはアプリケーションをpharファイル1つにまとめるコマンドがあります
つまり、ワンバイナリーでアプリケーションをデプロイ、実行する仕組みです
このpharの作成とデプロイの可能性を探ってみます

※(9/24:最後のスライドが発表時と異なっていたので差し替えました)

CyberAgent SGE Engineer

September 21, 2019
Tweet

More Decks by CyberAgent SGE Engineer

Other Decks in Technology

Transcript

  1. • גࣜձࣾαΠόʔΤʔδΣϯτ • 4(&౷ׅຊ෦ٕज़౷ׅࣨࣨ௕ • ࢠձࣾࣾ$50 • גࣜձࣾ$SBGU&HH • גࣜձࣾδʔΫϨετ

    • גࣜձࣾαϜβοϓ • നҪɹӳ • ΤϯδχΞ • #MPH IUUQBNFCMPKQHPPEPP ͓લɺ୭Α • 5XJUUFS !HPPEPP • %2 ͙ͪ͢Ή '# 
 ϓΫϦϙ ཱྀܳਓ
  2. $phar = new Phar('hoge.phar'); $phar->addFromString('hoge.php', file_get_contents('./hoge.php')); $phar->setStub("<?php define('IN_PHAR', true);\n Phar::mapPhar();\n

    require 'phar://hoge.phar/hoge.php'; \n __HALT_COMPILER();”); ࠷௿ݶͷ࣮ߦՄೳͳ 1IBSϑΝΠϧͷ࡞੒ྫ
  3. $phar = new Phar('hoge.phar'); $phar->addFromString('hoge.php', file_get_contents('./hoge.php')); $phar->setStub("<?php define('IN_PHAR', true);\n Phar::mapPhar();\n

    require 'phar://hoge.phar/hoge.php'; \n __HALT_COMPILER();”); IPHFQIQ͕࣮ߦՄೳͰ͋Ε͹ɺ ࡞੒ͨ͠IPHFQIBS΋ ࣮ߦՄೳͳϑΝΠϧʹͳΔ
  4. $phar = new Phar('hoge.phar'); $phar->addFromString('hoge.php', file_get_contents('./hoge.php')); $phar->setStub("<?php define('IN_PHAR', true);\n Phar::mapPhar();\n

    require 'phar://hoge.phar/hoge.php'; \n __HALT_COMPILER();”); BEE'SPN4USJOHͰඞཁͳϑΝΠ ϧΛQIBSʹ௥Ճ͍ͯ͘͠ͱ׬੒
  5. { "name": "goodoo/hoge-phar", "description": "hoge phar", "authors": [ { "name":

    "goodoo } ], "bin": [ "./hoge.php" ], "require": { "guzzlehttp/guzzle": "~6.0" } } DPNQPTFSKTPOʹʮCJOʯͷ߲໨ʹ ΤϯτϦʔϙΠϯτͱͳΔ QIQϑΝΠϧΛࢦఆ͢Δ͚ͩ
  6. •Base on Swoole extension •Built-in HTTP, TCP, WebSocket Coroutine Server

    •Powerful AOP (Aspect Oriented Programming) •Flexible and comprehensive annotations framework •Global dependency injection container •PSR-7 based HTTP message implementation •PSR-14 based event manager •PSR-15 based middleware •PSR-16 based cache design •Scalable high performance RPC •Holistic service governance, fallback, load balance, service registration and discovery •Database ORM •Universal connection pools •Mysql, Redis, RPC, HTTP Coroutine Clients •Coroutine driver client and blocking driver client seamlessly switch automatically •Coroutine and asynchronous task delivery •Custom user processes •RESTful supported •Internationalization (i18n) supported •High performance router •Fast and flexible parameter validator •Alias mechanism •Powerful log component •Cross-platform application auto- reload mechanism https://github.com/swoft-cloud/swoft ͷREADMEͷӳ༁ Ҿ༻ɿ
  7. $ php bin/swoft app:pack --help Description: pack project to a

    phar package Usage: bin/swoft app:pack [--dir DIR] [--output FILE] Options: --dir STRING Setting the project directory for packing. default is current work-dir.(/Users/a11924/Git/isucon8-swoft) --fast BOOL Fast build. only add modified files by git status -s --refresh BOOL Whether build vendor folder files on phar file exists(False) -o,--output STRING Setting the output file name(app.phar) -c, --config STRING Use the defined config for build phar. Example: bin/swoft app:pack Pack current dir to a phar file. bin/swoft app:pack --dir vendor/swoft/devtool Pack the specified dir to a phar file. BQQQBDL
  8. $ php app.phar start Server Information ******************************************************************** * HTTP |

    host: 0.0.0.0, port: 8888, type: 1, worker: 1, mode: 2 * TCP | host: 0.0.0.0, port: 8099, type: 1, worker: 1 (Disabled) ******************************************************************** Server has been started. (master PID: 7533, manager PID: 7534) You can use CTRL + C to stop run. ىಈʂ
  9. $ php bin/swoft app:pack --help Description: pack project to a

    phar package Usage: bin/swoft app:pack [--dir DIR] [--output FILE] Options: --dir STRING Setting the project directory for packing. default is current work-dir.(/Users/a11924/Git/isucon8-swoft) --fast BOOL Fast build. only add modified files by git status -s --refresh BOOL Whether build vendor folder files on phar file exists(False) -o,--output STRING Setting the output file name(app.phar) -c, --config STRING Use the defined config for build phar. Example: bin/swoft app:pack Pack current dir to a phar file. bin/swoft app:pack --dir vendor/swoft/devtool Pack the specified dir to a phar file. ŠGBTUΦϓγϣϯͷ ࠩ෼Ϗϧυͷར༻͕Αͦ͞͏