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

令和最新版 PHP メモリ管理術

memory
February 11, 2024
4k

令和最新版 PHP メモリ管理術

PHP カンファレンス関西 2024
PHP Memory Management in Reiwa

memory

February 11, 2024
Tweet

More Decks by memory

Transcript

  1. Ί΋Γʔ m3m0r7  memory1994 m3m0r7 1994 ೥ 5 ݄ੜ·Εɻෳ਺ͷελʔτΞοϓ ΍্৔اۀͰιϑτ΢ΣΞΤϯδχΞɼΤϯ

    δχΞϦϯάϚωʔδϟʔɼςοΫϦʔυɼ ࣥߦ໾һ CTO ͷܦݧΛܦΔɻ2023 ೥ 7 ݄ ΑΓגࣜձࣾΤϯϖΠͰιϑτ΢ΣΞΤϯδ χΞͱͯ͠ैࣄɻಉ೥ 10 ݄ΑΓΤϯδχΞ ϦϯάϚωʔδϟʔɻ
  2. 

  3. 

  4. 

  5. 

  6. 

  7. 

  8. ͦ΋ͦ΋ϝϞϦͬͯԿʁ - ྫ͑͹ AWS ͷΠϯελϯεΛબͿͱ͖ʹϝϞϦͷ߲໨ (r5.large ͳͲ)͕͋Δ ͔ͳͱࢥ͍·͕͢ɼͦΕͰ͢ɻͨͩɼϝϞϦͱݺͿͱ͖͸Ծ૝͔෺ཧ͔͋·Γ ؾʹ͍ͯ͠·ͤΜ -

    ࣮ࡍ͸ଞͷιϑτ΢ΣΞͳͲͰ΋ϝϞϦΛ࢖༻͍ͯ͠ΔͨΊɼࢦఆͨ͠ϝϞ Ϧ͕શͯ࢖͑Δͱ͸ݶΓ·ͤΜ - ͕ͨͬͯ͠ PHP Ͱ ini_set('memory_limit ', '4G') ͳͲͱ҆௚ʹ
 ࢦఆ͢Δͷ͸ϕετϓϥΫςΟεͱ͸ݴ͑·ͤΜɻ  ϝϞϦ͸ͳͥ଍Γͳ͘ͳΔͷ͔
  9. ىಈ͚ͩͰ΋ 2M ఔ౓࢖༻͍ͯ͠Δཧ༝ - PHP ͸ىಈ࣌ʹ 2M Ҏ্ͷϝϞϦΛͦ΋ͦ΋࢖༻͍ͯ͠·͢ɻ - ྫ͑͹ɼPHP

    ͷ࣮ߦͰ php -d memory_limit=1K -r "" ͱ͢ΔͱɼPHP ͦͷ ΋ͷ͕࣮ߦͰ͖ͳ͍ࣄ͕Θ͔Γ·͢ɻ  ϝϞϦ֬อͷ͘͠Έ php -d memory_limit=1K -r ""
  10. ىಈ͚ͩͰ΋ 2M ఔ౓࢖༻͍ͯ͠Δཧ༝ - memory_limit ͷॲཧ͸ https://github.com/php/php-src/blob/php-8.3.2/ main/main.c#L273 ͷ static

    PHP_INI_MH(OnChangeMemoryLimit) ͰߦΘ Ε͍ͯ·͢ɻ - ࠷ऴతʹ͸ Zend Memory Manager ͕ݺͼग़͞Εͯɼॲཧ͞Ε͍ͯ·͢ɻ - zend_alloc.c ͷ https://github.com/php/php-src/blob/php-8.3.2/Zend/ zend_alloc.c#L2731 Ͱ͋Δ zend_set_memory_limit Ͱ͢ɻ  ϝϞϦ֬อͷ͘͠Έ
  11. ىಈ͚ͩͰ΋ 2M ఔ౓࢖༻͍ͯ͠Δཧ༝ - ./con fi gure --disable-all ͰϏϧυ࣌ʹશͯͷϞδϡʔϧΛແޮԽʹͯ͠΋ɼ ಛஈϝϞϦ࢖༻ྔ͕ݮΔ͜ͱ͸͋Γ·ͤΜɻ

    - ϞδϡʔϧΛແޮʹͯ͠΋༗ޮʹͯ͠΋ɼৗʹ 2,097,152 όΠτ (2M)ɹ͕ফඅ ͞Ε͍ͯΔ͜ͱ͕Θ͔Γ·͢ɻ (Ubuntu 20 on Docker ͷ৔߹) - ͦΕ͸ͳͥͰ͠ΐ͏͔ɻ  ϝϞϦ֬อͷ͘͠Έ ./con fi gure --disable-all
  12. ىಈ͚ͩͰ΋ 2M ఔ౓࢖༻͍ͯ͠Δཧ༝ - Կ΋ॲཧΛ͍ͯ͠ͳ͍ͷʹ 2MB Λ࢖༻͍ͯ͠Δཧ༝͸ zend_alloc_sizes.h ͷ ZEND_MM_CHUNK_SIZE

    ͱ͍͏ఆ਺͕Ωʔͱͳ͓ͬͯΓɼ͜Ε͕ 2MB ͱͳ͍ͬͯΔ͔ΒͰ͢ - ࢀর: https://github.com/php/php-src/blob/php-8.3.2/Zend/ zend_alloc_sizes.h#L22 - PHP ͸ޮ཰Α͘ॲཧΛ͢ΔͨΊʹɼϝϞϦΛ֬อ͢Δࡍʹ͸͋Δఔ౓όοϑΝ Λ࣋ͬͯ֬อ͢ΔͷͰ͢ɻ  ϝϞϦ֬อͷ͘͠Έ
  13. ىಈ͚ͩͰ΋ 2M ఔ౓࢖༻͍ͯ͠Δཧ༝ - ZEND_MM_CHUNK_SIZE Λ 4MB ʹมߋ͠ɼPHP ΛϏϧυ͠ͳ͓ͯ͠ىಈ ͯ͠ΈΔͱͲ͏Ͱ͠ΐ͏͔ɻ

    - ͦΕʹ߹Θͤͯ memory_limit ΋ 3MB ʹม͑ͯΈ·͢ɻ  ϝϞϦ֬อͷ͘͠Έ 3MB ʹมߋ 4MB ࢖͍ͬͯΔ͜ͱ͕Θ͔Γ·͢
  14. ىಈ͚ͩͰ΋ 2M ఔ౓࢖༻͍ͯ͠Δཧ༝ - Ͱ͸ memory_limit Λਖ਼ৗʹىಈͰ͖͏ΔͰ͋Ζ͏ 5MB ʹม͑ͯΈ·͢ 

    ϝϞϦ֬อͷ͘͠Έ 5MB ʹมߋ ਖ਼ৗʹग़ྗ͞Ε͍ͯΔ͜ͱ͕
 Θ͔Γ·͢ ग़ྗ͞ΕΔ͔Λςετ͢ΔͨΊʹ echo ʹॻ͖׵͑ͯ·͢
  15. ىಈ͚ͩͰ΋ 2M ఔ౓࢖༻͍ͯ͠Δཧ༝ - ZEND_MM_CHUNK_SIZE ͸ Zend Memory Manager ʢZend

    MMʣͱݺ͹ ΕΔϝϞϦΛ؅ཧ͢ΔػߏʹΑͬͯޮ཰తʹϝϞϦΛΞϩέʔτʢAllocateɼ ϝϞϦͷྖҬΛ֬อ͢Δ͜ͱʣͤ͞·͢ɻ - ͜ͷػߏΛແޮʹ͠ɼҰൠతʹϝϞϦͷΞϩέʔτͰ༻͍ΒΕΔ malloc Λ࢖ ༻͢Δʹ͸ USE_ZEND_ALLOC=0 ͱ͍͏؀ڥม਺Λࢦఆ࣮ͯ͠ߦ͠·͢ɻ
 ※ PHP ͷϚχϡΞϧʹ͸ຊ൪؀ڥͰͷ࢖༻͸͠ͳ͍Α͏ॻ͔Ε͍ͯ·͢ɻ  ϝϞϦ֬อͷ͘͠Έ
  16. - PHP ͷϝϞϦ؅ཧԼͷ֎ʹͳΔͷͰɼmemory_get_usage ͳͲͷΑ͏ͳɼϝ ϞϦؔ࿈ͷؔ਺͕ɼ΄ͱΜͲಈ࡞͠ͳ͘ͳΓ·͢ɻ ىಈ͚ͩͰ΋ 2M ఔ౓࢖༻͍ͯ͠Δཧ༝  ϝϞϦ֬อͷ͘͠Έ

    USE_ZEND_ALLOC=0 Λࢦఆ͢ΔͱΤϥʔ͕ දࣔ͞Ε࣮ͣߦ͞ΕΔ͜ͱ͕Θ͔Γ·͢ ग़ྗ͞ΕΔ͔Λςετ͢ΔͨΊʹ echo ʹॻ͖׵͑ͯ·͢
  17. memory_get_usage/memory_get_peak_usage ͷ஋ʹ͍ͭͯ - memory_get_usage/memory_get_peak_usage ͸ true Λୈ 1 Ҿ਺ʹࢦఆ͠ ͨ৔߹ɼZEND_MM_CHUNK_SIZE

    ϕʔεʹͳΓ·͢ɻ - Zend MM ͕ͲΕ΄Ͳ࣮ࡍʹϝϞϦΛ֬อ͍ͯ͠Δͷ͔Λ஌Γ͍ͨ৔߹ʹ༗ ༻Ͱ͢ɻ - ͳ͓ɼPHP ͷϓϩηε͕࢖͍ͬͯΔϝϞϦফඅྔͰ͸͋Γ·ͤΜͷͰ஫ҙ ͕ඞཁͰ͢ɻ  ϝϞϦ֬อͷ͘͠Έ
  18. memory_get_usage/memory_get_peak_usage ͷ஋ʹ͍ͭͯ - ͦͷதͷ௨ৗͷϝϞϦফඅྔΛಘ͍ͨ৔߹͸ ୈ 1 Ҿ਺ʹ͸ಛஈࢦఆ͠ͳ͍΄ ͏͕ྑ͍Ͱ͢ɻ - ୈҰҾ਺Λࢦఆ͠ͳ͍৔߹ͷϢʔεέʔεͱͯ͠͸ɼྫ͑͹ಛఆͷॲཧͷൣ

    ғͰͲΕ͘Β͍ϝϞϦ͕ফඅ͞Ε͍ͯΔͷ͔Λ஌Γ͍ͨਓ޲͚ʹ༗༻Ͱ͢ɻ - PHP ͷϓϩηεຊମͷϝϞϦ࢖༻ྔͰ͸ͳ͍ͨΊ memory_limit ಺ʹϝϞ Ϧͷ࢖༻ྔΛऩΊΔͨΊͷϘτϧωοΫΛ୳͢༻్͘Β͍͔͠ࢲ͸ࢥ͍ු͔ ͹ͳ͍Ͱ͕͢…ɻଞʹ͜͏͍͏༻్͕͋ΔΑͳͲ͋Ε͹ڭ͍͑ͯͩ͘͞ʂ  ϝϞϦ֬อͷ͘͠Έ
  19. memory_get_usage/memory_get_peak_usage ͷ஋ʹ͍ͭͯ - ୈ 1 Ҿ਺ʹ true Λ౉͞ͳ͔ͬͨ৔߹ ϝϞϦ֬อͷ͘͠Έ ஋ʹมԽ͋Γ


    ʢͨͩ͠಺෦ͰͷϝϞϦফඅྔ͸มԽͳ͠ʣ ஋ʹมԽ͋Γ
 ʢͨͩ͠಺෦ͰͷϝϞϦফඅྔ͸มԽͳ͠ʣ
  20. memory_get_usage/memory_get_peak_usage ͷ஋ʹ͍ͭͯ - ͜ΕΒͷ஋͸ Zend Memory Manager ͕ϕʔεͱͳ͍ͬͯΔͨΊ
 USE_ZEND_ALLOC=0 ͱͨ͠৔߹͸ৗʹ

    0 ͕ฦΓ·͢ɻ - ·ͨɼ͜Ε͸ PHP ͕ϓϩηεͱͯ͠࢖༻͍ͯ͠ΔϝϞϦফඅྔͰ͸ͳ͍ ʢZend Memory Manager ্Ͱ͋ΔͨΊʣͨΊϓϩηεͦͷ΋ͷ͕࢖༻ͯ͠ ͍ΔϝϞϦফඅྔΛ஌Γ͍ͨ৔߹͸ɼҟͳΔखஈ͕ඞཁͰ͢ɻ - ஫) USE_ZEND_ALLOC=0 ͸ɼϝϞϦϦʔΫݕग़࣌Ҏ֎ʹ࢖͏΂͖΋ͷͰ͸ͳ͍ͱ PHP ϚχϡΞϧʹهࡌ͞Ε͍ͯ·͢ɻ
 ࢀর: http://php.adamharvey.name/manual/ja/internals2.memory.management.php  ϝϞϦ֬อͷ͘͠Έ
  21. memory_get_usage/memory_get_peak_usage ͷ஋ʹ͍ͭͯ - PHP ͷϓϩηεͦͷ΋ͷ͕ར༻͍ͯ͠ΔϝϞϦ࢖༻ྔΛٻΊ͍ͨ৔߹͸ҎԼ ͷΑ͏ʹ͢Δ͜ͱͰऔಘͰ͖·͢ɻ - VSS (Virtual Set

    Size, ϓϩηε͕֬อ͍ͯ͠ΔԾ૝ϝϞϦͷαΠζ) - system("ps u -p" . getmypid() . " | grep php | awk '{print $5}'"); - RSS (Resident Set Size, ϓϩηε͕༧Ί֬อ͍ͯ͠Δ෺ཧϝϞϦͷαΠζ) - system("ps u -p" . getmypid() . " | grep php | awk '{print $6}'");  ϝϞϦ֬อͷ͘͠Έ system("ps u -p" . getmypid() . " | grep php | awk '{print $5}'"); system("ps u -p" . getmypid() . " | grep php | awk '{print $6}'");
  22. ༨ஊ: POST ͷαΠζʹ͍ͭͯ - ଞʹ΋ૹΒΕͯ͘Δ POST ͷαΠζΛܾఆ͢Δ post_max_size ͳͲ͕͋Γ· ͢ɻ

    - ͜Ε͸Ұ࣌ϑΝΠϧͱͯ͠࡞੒͞ΕΔͨΊɼmemory_limit > post_max_size Ͱ͋Δඞཁ͸͋Γ·ͤΜɻ - php -d memory_limit=4M -d post_max_size=16M -S 0.0.0.0:8000 ͰϏϧ τΠϯαʔόʔΛىಈ͠ɼ࣮ࡍʹ 4MB ΑΓେ͖͍ϑΝΠϧΛૹ৴ͯ͠΋ɼ ໰୊ͳ͍͜ͱ͕֬ೝͰ͖·͢ɻ  ϝϞϦ֬อͷ͘͠Έ
  23. ༨ஊ: POST ͷαΠζʹ͍ͭͯ - ͨͩ͠ɼSAPI_POST_BLOCK_SIZE (σϑΥϧτ 16,384 bytes) ෼ͷϝϞϦ͸ ʢZend

    Memory Manager ͷ֎Ͱʣ࢖༻͞Ε·͢ɻ - ͜ͷ஋ʹ͍ͭͯ͸ memory_get_usage ͳͲͰ͸औಘͰ͖·ͤΜɻPHP ͷ಺ ෦ґଘͷ࣮૷ʹͳΓ·͢ɻ - memory_get_usage ͸ɼҰ෦ྫ֎Λআ͖·͕͢ɼجຊతʹ͸Ϣʔβʔϥϯυ ͷίʔυͷϝϞϦ࢖༻ྔ͕ੵ·Ε͍ͯ͘͜ͱʹ஫ҙ͢Δඞཁ͕͋ΔͷͰ͢ɻ  ϝϞϦ֬อͷ͘͠Έ
  24. ༨ஊ: POST ͷαΠζʹ͍ͭͯ - ͜Ε͸ post_max_size >= upload_max_ fi lesize

    Ͱ͋Δඞཁ͕͋Γ·͢ɻ post_max_size ͕શମͷ POST ͷαΠζΛࢦఆ͢Δͷʹରͯ͠ɼ upload_max_ fi lesize ͸ POST ͷதͷૹ৴͞Εͨ multipart Λࢀর͢ΔͨΊͰ ͢ɻ - ͳ͓ɼ͜Ε͸ 1 ϑΝΠϧ͋ͨΓͰ͸ͳ͘ɼશͯͷϑΝΠϧͷαΠζͷ߹ܭ Ͱ͢  ϝϞϦ֬อͷ͘͠Έ
  25. PHP ͷϝϞϦͱม਺ͷؔ܎ - $tmp ʹจࣈྻΛ୅ೖ͍ͯͯ͠΋ɼͦ ͷ৔Ͱ͸ Zend MM ্ͰϝϞϦফඅ ྔ͸Ճࢉ͞Ε·ͤΜɻ

    - ·ͨɼ$tmp2 ΋ PHP ͸ CoW (Copy on Write) Ͱ͋ΔͨΊɼಉ༷ʹ ͜ͷ࣌఺Ͱ΋ϝϞϦͷফඅྔ͸Ճࢉ ͞Ε·ͤΜɻ  ϝϞϦ֬อͷ͘͠Έ
  26. PHP ͷϝϞϦͱม਺ͷؔ܎ - ϓϦϛςΟϒͳ஋Λࢦఆ͢Δ৔߹ͱɼؔ਺ݺͼग़͕͋͠Δ৔߹Ͱ͸·ͬͨ͘ ΋ͬͯҧ͏ͱ͍͏͜ͱ͕Θ͔Γ·͢ɻ - ྫ͑͹͜ΕΛ int ܕ΍ array

    ܕͷ஋ʹஔ͖׵͑ͨΒ 0 ͱग़ྗ͞ΕΔ͜ͱ͕Θ͔ Γ·͢ɻͪͳΈʹ memory_get_peak_usage Ͱ΋ಉ༷Ͱ͢ɻ - ͭ·Γɼ͋ͨΓ·͑Ͱ͸͋Γ·͕͢ɼؔ਺ݺͼग़͠͸ۃྗ߇͑ͯɼϓϦϛςΟ ϒܕͰͳΔ΂͘ॲཧ͢Δ΄͏͕ϝϞϦͱ͍͏؍఺Ͱ͸ޮ཰తͩͱݴ͑·͢ɻ  ϝϞϦ֬อͷ͘͠Έ
  27. PHP ͷϝϞϦͱม਺ͷؔ܎ - ϝϞϦফඅྔ͸ 4,210,928 bytes ͱͳΓɼ216 bytes ૿͑Δ͜ͱ͕Θ͔Γ· ͢ɻ

    - 2 ࣍ݩ഑ྻɼ3 ࣍ݩ഑ྻͱ૿΍͍ͯ͘͠ͱɼϝϞϦফඅྔ͕૿͍͖͑ͯ·͢ - ഑ྻʹ͢Δ͚ͩͰ΋࢖༻ྔ͕มΘΔͱ͍͏͜ͱ͕Θ͔Γ·͢ɻ - จࣈྻܕ΍഑ྻܕͳͲ͕Ͳͷ͘Β͍ϝϞϦΛ࢖͏͔ʹ͍ͭͯ͸
 zend_types.h ʹهࡌ͞Ε͍ͯ·͢  ϝϞϦ֬อͷ͘͠Έ
  28. PHP ͷϝϞϦͱม਺ͷؔ܎  ϝϞϦ֬อͷ͘͠Έ - ·ͨɼint ܕ ΍ string ܕͩͬͨΒৗʹ

    0 ͔ͱ ͍͏ͱɼͦ͏͍͏Θ͚Ͱ͸͋Γ·ͤΜɻ - ӈਤͷΑ͏ʹจࣈྻΛ 3MB ॻ͖ग़ͨ͠
 ϑΝΠϧΛ࡞੒͠ɼ࣮ࡍʹ࣮ߦ͢Δͱ
 ҎԼͷΑ͏ʹΤϥʔ͕ग़·͢
  29. GC ͱ ऑࢀরʢWeakrefʣ  ($ (BSCBHF$PMMFDUJPO ΨϕʔδίϨΫγϣϯ ͸ɼҰఆͷ৚݅Λຬͨͨ͠ ৔߹ʹɼม਺΍஋ͷϝϞϦղ์Λߦ͏΋ͷͰ͢ 

    1)1ʹ͸SFGDPVOUʢϦϑΝϨϯεΧ΢ϯτʣͱݺ͹ΕΔɼ͍Θ͹ม਺ͷݺͼ ग़͠ճ਺Λه࿥͢Δػೳ͕͋Γɼ͜ͷ஋Λ༻͍ͯɼ($ͷର৅Ͱ͋Δ͔Ͳ͏͔ Λ൑ఆ͍ͯ͠·͢  ࢀরIUUQTXXXQIQOFUNBOVBMKBGFBUVSFTHDSFGDPVOUJOH CBTJDTQIQ  ϝϞϦ֬อͷ͘͠Έ
  30. memory_limit ͷϕετϓϥΫςΟε - 2*N ʢN ͸ࣗવ਺ʣMB Λߟྀͯ͠ memory_limit ઃఆΛ͠·͠ΐ͏ɻ -

    ͦ΋ͦ΋ memory_limit ͷԼݶ͸ 2MB (ZEND_MM_CHUNK_SIZE ʹΑΔ)ͳ ͷͰɼϝϞϦফඅྔ 2MB Ҏ಺Ͱॲཧ͕ॻ͚Δͱϕετ - ͜Ε͸ memory_limit ͷσϑΥϧτ 128MB Ͱ͋ͬͯ΋ɼॳճͷղ์͞ΕΔ ஋͕ 2MB ͱ͍͏͜ͱͰ͢ɻ  ϝϞϦফඅྔΛ࡟ݮ͢Δʹ͸
  31. memory_limit ͷϕετϓϥΫςΟε - 2MB+1B ͔͠࢖ͬͯͳ͍Α͏ʹݟ͑ͯ΋ɼཪͰ͸݁ہ 2MB (ZEND_MM_CHUNK_SIZE) * 2 =

    4MB ϝϞϦΛফඅͯ͠ΔΘ͚Ͱ͢ɻ - memory_get_usage(false) ͳͲͷ஋ΛνϚνϚվળͯ͠΋ɼ݁ہϝϞϦ͸ ফඅ͞Ε͍ͯΔͷͰҙຯ͕͋Γ·ͤΜɻ࣌ؒΛ࢖͏͚ͩແବͰ͢ɻ - ͜ͷΑ͏ͳέʔε͸ 4MB ϑϧʹ࢖ͬͨ΄͏͕ޮ཰తͰ͢ɻ - ͭ·ΓɼPHP ʹ͓͚Δ memory_limit ͸ 2MB ͷഒ਺Λઃఆ͠ɼͦͷ஋ ͷதͰ࢖ͬͯ͋͛Δͷ͕࠷΋ޮ཰తͰޮՌతͰ͢ɻ  ϝϞϦফඅྔΛ࡟ݮ͢Δʹ͸
  32. memory_limit ͷϕετϓϥΫςΟε - ྫ͑͹ AWS Λ࢖༻͍ͯ͠ΔํͰ c5.large Λબఆ͍ͯ͠Δ৔߹͸ϝϞϦ͸ 4GB ͱͳΔͷͰɼphp-fpm

    ͳͲͷଞϓϩηεͷϝϞϦ࢖༻ྔ΋Ճຯ্ͨ͠Ͱ - 2M * N (1 <= N < (4G/2), N ͸ࣗવ਺) ͳͲͱݟੵ΋Δͱྑ͍Ͱ͠ΐ͏ɻ - ࡢࠓͷΞϓϦέʔγϣϯ͸ΨϕʔδίϨΫγϣϯʹ೚͖ͤΓͰɼϝϞϦϦʔΫ Λසൟʹى͍ͯͨ͜͠Γ΋͠·͢ɻΏ͑ʹɼطଘͷΞϓϦέʔγϣϯͷঢ়ଶ΋ ΋ͪΖΜՃຯ͢Δ͜ͱ͕ॏཁͰ͢ɻ  ϝϞϦফඅྔΛ࡟ݮ͢Δʹ͸
  33. memory_limit ΑΓ΋େ͖ͳ஋Λ࢖͍͍ͨ - εϫοϓ΍όοϑΝΛ͏·͘ѻ͏͜ͱͰɼmemory_limit ΑΓ΋େ͖ͳ஋Λ࢖ ͏͜ͱ͕ՄೳͰ͢ɻ - ྫ͑͹ memory_limit Λ

    2M ͱࢦఆ͍ͯ͠Δ৔߹͸Ծఆ͠·͢ɻ͜ͷέʔεͷ ͱ͖ɼ 4M ͷϑΝΠϧͷத਎Λग़ྗ͠Α͏ͱ
 `echo fi le_get_contents('test_heavy.log')` ͷΑ͏ʹ۪௚ʹॻ͘ͱϝϞϦ͕ෆ ଍ͯ͠͠·͍·͢ɻ - ࣍ͷϖʔδͷΑ͏ʹ෼ׂͯ͋͛͠Δ͜ͱͰϝϞϦফඅྔΛ཈͑Δ͜ͱ͕ՄೳͰ ͢ɻ  ϝϞϦফඅྔΛ࡟ݮ͢Δʹ͸ echo fi le_get_contents('test_heavy.log')
  34. memory_limit ΑΓ΋େ͖ͳ஋Λ࢖͍͍ͨ - PHP Λհͯ͠ը૾Λ base64 ͱͯ͠ग़ྗ͍ͨ͠έʔεͳͲ΋͋Δ͔ͱࢥ͍· ͢ɻ - ϑΝΠϧαΠζ͕খ͍͞ɼ΋͘͠͸ఆ·͍ͬͯΔͷͳΒ͹ɼ·ͩڐ༰Ͱ͖·͢

    ͕ɼϑΝΠϧαΠζ͕େ͖͍৔߹͸Ұ޻෉͕ඞཁͰ͢ɻ - ಛʹ PHP ͕ϏϧτΠϯͰఏڙ͍ͯ͠Δbase64_encode/base64_decode ͸શ ͯͷจࣈྻΛ౉͢ඞཁ͕͋Γ·͢ɻ  ϝϞϦফඅྔΛ࡟ݮ͢Δʹ͸
  35. memory_limit ΑΓ΋େ͖ͳ஋Λ࢖͍͍ͨ - 57 * 143 bytes ͝ͱʹ෼ׂͨ͠จࣈྻΛ base64_encode ͢Δ͜ͱ͕࣮͸Մೳ

    Ͱ͢ɻ͜Ε͸ base64 ΤϯίʔσΟϯάͷ࢓૊Έʹଇͬͨͪΐͬͱٕͨ͠Ͱ ͢ɻ - ࢀর: https://www.php.net/manual/ja/function.base64- encode.php#111942 - ຊ౰͸͜ΜͳখखઌͷٕΛ࢖͏ͷͰ͸ͳ͘ɼCDN ʹஔ͘ͳͲΞʔΩςΫνϟ ͱͯ͋͠Δ΂͖࢟͸໨ࢦ͍͖͍ͯͨ͠΋ͷͰ͢ɻ  ϝϞϦফඅྔΛ࡟ݮ͢Δʹ͸