Swooleで実装するPHP非同期処理の世界/phpcondo2019-swoole

83f9862ef4599c97e99d020eb8e20d87?s=47 KOYAMA Tetsuji
September 21, 2019

 Swooleで実装するPHP非同期処理の世界/phpcondo2019-swoole

2019-09-21 に開催されたPHPカンファレンス北海道2019で発表した資料です。

83f9862ef4599c97e99d020eb8e20d87?s=128

KOYAMA Tetsuji

September 21, 2019
Tweet

Transcript

  1. 4XPPMFͰ࣮૷͢Δ 1)1ඇಉظॲཧͷੈք খࢁ఩ࢤ !LPZIPHF PHPΧϯϑΝϨϯε๺ւಓ2019 2019-09-21

  2. PHPΧϯϑΝϨϯε๺ւಓ2019 2019-09-21 ࣗݾ঺հ খࢁ఩ࢤ ͜΍·ͯͭ͡  ߹ಉձࣾ΄ٕ͛ݚ Ϣʔβձ͍͔ͭ͘ ೔ຊ6/*9Ϣʔβձ ೔ຊ1PTUHSF42-Ϣʔβձ

    ೔ຊ1)1Ϣʔβձ SBLVNPגࣜձࣾΤϯδχΞ !LPZIPHF LPZIPHF
  3. ʮখࢁ͞Μ͸ ɹͲ͜ʹͰ΋͍·͢Ͷʯ

  4. ʮͲ͜ʹͰ΋͸͍ͳ͍Θɺ ͍Δͱ͜Ζʹ͚ͩʯ

  5. PHPΧϯϑΝϨϯε๺ւಓ2019 2019-09-21 ͯ͞ 4XPPMF

  6. PHPΧϯϑΝϨϯε๺ւಓ2019 2019-09-21 ʜͷલʹ

  7. PHPΧϯϑΝϨϯε๺ւಓ2019 2019-09-21 ࣮ߦ଎౓ͷ௿ԼཁҼ w$16 wϝϞϦ wϩδοΫ wσʔλॲཧྔ w*0
 

  8. PHPΧϯϑΝϨϯε๺ւಓ2019 2019-09-21 *0 w$16ॲཧʹൺ΂Δͱஈҧ͍ʹ஗͍ wऴྃ଴ͪঢ়ଶ wಉظॲཧ

  9. PHPΧϯϑΝϨϯε๺ւಓ2019 2019-09-21 Gregg, Brendan. “Systems Performance: Enterprise and the Cloud.”

    *0஗Ԇ
  10. PHPΧϯϑΝϨϯε๺ւಓ2019 2019-09-21 ඇಉظ*0 w*0ॲཧͷऴྃΛ଴ͨͳ͍ wϒϩοΫ͠ͳ͍ wͦͷؒʹଞͷॲཧΛ͢Δ w*0ॲཧ͕ऴΘͬͨΒͦͪΒʹ໭Δ

  11. PHPΧϯϑΝϨϯε๺ւಓ2019 2019-09-21 https://twitter.com/php_swoole/status/1060181279407169538

  12. PHPΧϯϑΝϨϯε๺ւಓ2019 2019-09-21 1)14XPPMF $PSPVUJOFCBTFEDPODVSSFODZMJCSBSZGPS1)1 https://www.swoole.co.uk/ https://github.com/swoole/swoole-src/ @php_swoole

  13. PHPΧϯϑΝϨϯε๺ւಓ2019 2019-09-21 4XPPMFͱ͸ wඇಉظॲཧΛجຊʹͨ͠ߴ଎Խॲཧͷ ٧Ί߹ΘͤϥΠϒϥϦ w೥͔Β։ൃ wݩ͸ӳࠃ5SBOTGPOʹΑͬͯ wݱࡏ͸தࠃݍͷ։ൃऀ͕໠྽ʹ

  14. PHPΧϯϑΝϨϯε๺ւಓ2019 2019-09-21 1)14XPPMF w Φʔϓϯιʔε "QBDIFϥΠηϯε  w 1)1&YUFOTJPO w

    $$ #PPTU$POUFYU w ίʔϧόοΫίϧʔνϯ w Πϕϯτۦಈͷඇಉظ*0 w )551)5518FC4PDLFU5$16%1 w ϚΠΫϩඵλεΫεέδϡʔϥ w ϓϩηεϚωʔδϟ w ϓϦΤϯϓςΟϒεέδϡʔϦϯά
  15. PHPΧϯϑΝϨϯε๺ւಓ2019 2019-09-21 Πϯετʔϧ $ pecl install swoole extension=swoole.so ZPVSJOJ

  16. PHPΧϯϑΝϨϯε๺ւಓ2019 2019-09-21 ࠷ॳͷҰา $ php co.php start coro 1 start

    to resume 1 @1 resume coro 1 @1 start to resume 1 @2 resume coro 1 @2 main
  17. PHPΧϯϑΝϨϯε๺ւಓ2019 2019-09-21 ղઆ w4XPPMFa$PSPVUJOFʹ͸$Pͱ͍͏ΤΠϦ Ξε͕͍͍ͭͯΔ w࠷ॳͷVTFจ͸ͳͯ͘΋ಈ͘ w1)1͸Ϋϥε໊ͷେখจࣈ͸۠ผ͠ͳ͍ wHP ͸4XPPMFa$PSPVUJOFDSFBUF ͷΤ

    ΠϦΞε
  18. PHPΧϯϑΝϨϯε๺ւಓ2019 2019-09-21 ղઆ wDPZJFME ͸ॲཧΛҰ୴தஅ͢Δ wDPSFTVNF ͸ର৅͕ZJFME ͢Δ·Ͱϒϩο Ϋ͢Δ

  19. PHPΧϯϑΝϨϯε๺ւಓ2019 2019-09-21 4XPPMFίϧʔνϯ w4XPPMFͷඇಉظॲཧͷࠜװ wதஅ࠶։Ͱ͖Δॲཧ୯Ґ w4XPPMFͰ͸γϯάϧεϨουͰ࣮૷ ͞Ε͍ͯΔ

  20. PHPΧϯϑΝϨϯε๺ւಓ2019 2019-09-21 swoole-src/include/coroutine.h ࣮૷ͷத֩෦෼

  21. PHPΧϯϑΝϨϯε๺ւಓ2019 2019-09-21 ίϧʔνϯྫ $ php co2.php write...: data/00.out write...: data/01.out

    write...: data/02.out write...: data/03.out write...: data/04.out write: data/00.out done write: data/01.out done write: data/02.out done write: data/03.out done write: data/04.out done
  22. PHPΧϯϑΝϨϯε๺ւಓ2019 2019-09-21 EFGFS wίϧʔνϯͷऴྃॲཧ wίϧʔνϯ͕FYJU͢Δ·Ͱ࣮ߦ͞Εͳ ͍ w࠷ޙʹݺ͹ΕͨEFGFS͔Βٯॱʹ࣮ߦ ͞ΕΔ

  23. PHPΧϯϑΝϨϯε๺ւಓ2019 2019-09-21 EFGFSͷྫ $ php defer.php abc~b~a

  24. PHPΧϯϑΝϨϯε๺ւಓ2019 2019-09-21 DIBO wνϟϯωϧΛ࡞੒͢Δ wίϧʔνϯؒͷϝοηʔδड͚౉͠

  25. PHPΧϯϑΝϨϯε๺ւಓ2019 2019-09-21 DIBOͷྫ

  26. PHPΧϯϑΝϨϯε๺ւಓ2019 2019-09-21 https://speakerdeck.com/team/swoole-4-introducing-the-new-coroutine-design-pattern-in-php?slide=26

  27. PHPΧϯϑΝϨϯε๺ւಓ2019 2019-09-21 4XPPMF4FSWFS w)551 w)551 w8FC4PDLFU w5$16%16OJY4PDLFU w3FEJT

  28. PHPΧϯϑΝϨϯε๺ւಓ2019 2019-09-21 )5514FSWFS

  29. PHPΧϯϑΝϨϯε๺ւಓ2019 2019-09-21 5$14FSWFS

  30. PHPΧϯϑΝϨϯε๺ւಓ2019 2019-09-21 ·ͱΊ w4XPPMF͸1)1ߴ଎Խͷ৽͍͠ํ޲ੑ wඇ࿈ଓతਐԽ w׆ൃʹ։ൃ͞Ε͍ͯΔ༷ࢠΛோΊ͍ͯ Δ͚ͩͰ΋ָ͍͠ wʮ1)1Ͱ͜͜·ͰͰ͖Δʯͱূ໌ͨ͠ ͜ͱʹܟҙΛධ͍ͨ͠

  31. PHPΧϯϑΝϨϯε๺ւಓ2019 2019-09-21 એ఻ w ݄຤ʹٕज़ධ࿦ࣾΑΓʮΈΜͳͷ1)1ʯ͕ग़·͢ w 1)1ΛςʔϚʹͨ͠ϜοΫ w ϖʔδલޙ w

    Ձ֨ະఆ w 4PGUXBSF%FTJHO೥݄߸ ൃച  w λΠΞοϓಛू1 w 8&# %#13&44WPM ൃച  w 4XPPMFʹؔ͢ΔλΠΞοϓهࣄ1
  32. PHPΧϯϑΝϨϯε๺ւಓ2019 2019-09-21 3FG w IUUQTTXPPMFDPVL w IUUQTHJUIVCDPNTXPPMFTXPPMFTSD w IUUQTTQFBLFSEFDLDPNUFBNQSFFNQUJWF NVMUJUBTLJOHVTJOHDPSPVUJOFTJOQIQTXPPMF

    w IUUQTTQFBLFSEFDLDPNUFBNTXPPMF JOUSPEVDJOHUIFOFXDPSPVUJOFEFTJHOQBUUFSOJO QIQ