æè¿ãAvito PHPãããžã§ã¯ãã¯PHP 7.1ã«åãæ¿ãããŸããã ãã®æ©äŒã«ãç§ãã¡ãšOLXã®ååãšã§PHP 7.0ãžã®ç§»è¡ãã©ã®ããã«è¡ãããããæãåºãããšã«ããŸããã éå»ã®äŸã§ãããäžçã«èŠãããçŸããã°ã©ãã£ãã¯ããããŸããã
ã¹ããŒãªãŒã®æåã®éšåã¯ã æ»ãã§ããªãPHPã®èšäºã«åºã¥ããŠããŸãïŒ OLXÅukaszSzymaÅski ïŒLukasz SzymanskiïŒã®ååã«ãã£ãŠæžãããPHP7ã®å®è·µ ïŒOLXããPHP 7ãžã®ç§»è¡
ããŒã1. OLXã®PHP 7
OLX Europeã¯10ã®Webãµã€ããéå¶ããŠããããã®ãã¡æ倧ã®ãã®ã¯OLX.plã§ãã ãã¹ãŠã®ãµã€ãã¯å¯èœãªéãå¹ççã«åäœããå¿ èŠããããããPHP 7ãžã®ç§»è¡ãæåªå äºé ã«ãªããŸããã
ãã®æçš¿ã§ã¯ãPHP 7ãžã®ç§»è¡ã§çŽé¢ããåé¡ãšå¯ŸåŠæ¹æ³ã«ã€ããŠèª¬æããŸãã移è¡ã«ã€ããŠã¯ãPHPers Summit 2016ã«ã³ãã¡ã¬ã³ã¹ã§è°è«ãããŸããã
移è¡
ç§ãã¡ã®äžå®ã«åããŠã移è¡ã¯ã¹ã ãŒãºã«é²ã¿ãŸããã å ¬åŒããã¥ã¡ã³ãããã®å¿ èŠãªå€æŽã®æšæºãªã¹ããé€ããŠãç§ãã¡ã®ã¢ãŒããã¯ãã£ã«é¢é£ããããã€ãã®å€æŽãè¡ãã ãã§ããã
10ã®ãµã€ããç°ãªãåœã§éå¶ãããŠããããšã«èšåãã䟡å€ããããŸãã ãããŠãå€æŽãé çªã«å±éããŸãã次ã ã«ãµã€ãã§ã ãã®ã¢ãããŒãã¯ã倧ããªå€æŽã«ãšã£ãŠç¹ã«éèŠã§ãã
æå°ã®ãµã€ãããããŒãžã§ã³ã®æŽæ°ãéå§ãããã倧ããªãµã€ãã«ç§»è¡ããŠããã¹ããæåããããšã確èªããŸããã ããã«ãããäºæããªãåé¡ã®çºçãç£èŠããæœåšçãªæå·ãæžããããšãã§ããŸããã
Memcache
PHP 7ã§ã®MemcacheãµããŒãã®æŸæ£ã«ãããMemcachedãžã®ç§»è¡ãä¿ãããŸããã ãµã€ãã®2ã€ã®ããŒãžã§ã³ããµããŒãããå¿ èŠããããŸããïŒPHP 5 + Memcacheããã³PHP 7 + Memcachedã
ãã®åé¡ã解決ããããã«ã圌ãã¯åçŽãªã©ãããŒã䜿çšããŸããã 圌女ã¯ãã³ãŒããå®è¡ãããŠãããµãŒããŒã«é¢ããæ å ±ã«åºã¥ããŠããã£ãã·ã¥ã«æ¥ç¶ããããã®é©åãªPHPã¢ãžã¥ãŒã«ãéžæããŸãã
<?php $factory = new CacheWrapperFactory(); $factory->createServer( extension_loaded('memcache') ? 'memcache' : 'memcached', $uri );
ããããMemcachedã§ã®åéºã¯ããã§çµãããŸããã§ããã Memcacheã䜿çšããŠã·ãªã¢ã«åããããªããžã§ã¯ãã¯ãMemcachedã䜿çšããŠéã·ãªã¢ã«åã§ããªãããšãå€æããŸããã
ãã ãããã£ãã·ã¥ã¯ãã£ãã·ã¥ã§ãããç°¡åã«åé€ã§ããŸãã ãããã£ãŠãå€ãåé¡ã®ãããªããžã§ã¯ãããã£ãã·ã¥ããåé€ããæ°ããã¢ãžã¥ãŒã«ã䜿çšããŠåäœæããŸããã
APCãAPCuãããã³OPCache
çšèªã«ã€ããŠå°ãã
APCïŒä»£æ¿PHPãã£ãã·ã¥ïŒã¯ããã€ãã³ãŒããšãŠãŒã¶ãŒããŒã¿ã®ãã£ãã·ã¥ã§ãã
APCuïŒAPCãŠãŒã¶ãŒãã£ãã·ã¥ïŒ-ãŠãŒã¶ãŒããŒã¿ã®ãã£ãã·ã¥ã®ã¿ã
OPCacheã¯ãã€ãã³ãŒããã£ãã·ã¥ã®ã¿ã§ãã
PHP 7ã«ã¯APCã¯ãããŸãããAPCuãšOPCacheã®äž¡æ¹ã䜿çšããå¿ èŠããããŸããã 以åã¯ããã£ãã·ã¥ç®¡çãã¬ãŒã ã¯ãŒã¯ã®å€ãã®éèŠãªéšåã§APC APIã䜿çšããŠãããããAPC APIãšäºææ§ã®ããapcu-bcã¢ãžã¥ãŒã«ãAPCuã«åºå®ããŸããã
çµæ
以äžã¯ãåœç€Ÿã®æ倧ã®ãµã€ãã§ããOLX.plã®çµæã§ãã
Apacheã®CPU
WebãµãŒããŒïŒApacheïŒã¯ããããã32ã®ããã»ããµã³ã¢ãåãã20å°ã®ç©çãã·ã³ã§å®è¡ãããŸãã 移è¡ã®çµæãšããŠã®ããŒã¯ããã»ããµæ¶è²»ã¯ã50ïŒ ãã20ïŒ ã«æžå°ããŸããã
Apacheã®LA
åæ§ã«ãWebãµãŒããŒã®è² è·å¹³åãæžå°ããŸããã
æ°å€ã¯ãè² è·ã軜æžãããªãœãŒã¹ãç¯çŽããå¹çãåäžãããããšãè¡šããŠããŸãã ãããžã§ã¯ããããŒãžã£ãŒãŸãã¯ã¯ã©ã€ã¢ã³ãã移è¡ã«ååãªæéãäžããŠããªãå Žåããããã®ã¹ã±ãžã¥ãŒã«ã§ç¢ºå®ã«çŽåŸã§ããŸãã
PHP 7ã®ããã©ãŒãã³ã¹ã®çç±
ãã®ãããªå°è±¡çãªçµæã¯ã3ã€ã®äž»èŠãªé åã§ã®æé©åã«ãã£ãŠéæãããŸããã
å°ãªãã¡ã¢ãªå²ãåœãŠæäœ
PHP 5ã¯ãã¡ã¢ãªå²ãåœãŠæäœã§ã®ã¿æ¶è²»ããããã»ããµæéã®20ïŒ ãè²»ãããŸããã èšèªéçºè ã¯ããã«æ³šæãåèµ·ããã¡ã¢ãªå²ãåœãŠæäœã®æ°ãæžãããããã»ããµã®æ¶è²»ãå€§å¹ ã«æžãããŸããã
å°ãªãã¡ã¢ãªæ¶è²»
ãã®ã¹ã±ããã¯ãããã»ããµãã©ã³ãã ã¢ã¯ã»ã¹ã¡ã¢ãªïŒRAMïŒã«ã¢ã¯ã»ã¹ããããã«å¿ èŠãªãã¹ã瀺ããåã¹ãããã®æéã瀺ããŠããŸãã ã芧ã®ãšãããRAMãžã®ã»ã°ã¡ã³ãã¯æé·ã§ãã PHPéçºè ã¯ãã¢ããªã±ãŒã·ã§ã³ã®å¿çãé«éåããããšã§ã¡ã¢ãªäœ¿çšéãåæžããŸããã
äžéãã€ã³ã¿ãŒãå°ãªã
PHP 7ã®ããã©ãŒãã³ã¹ãæ¹åããæåŸã®çç±ã¯ãäžéãã€ã³ã¿ãŒã®æ°ã®æžå°ã§ãã ãããè¡ãããã«ãPHPéçºè ã¯ä»ã®ãã€ã³ã¿ãŒãåç §ããå€ãã®ãã€ã³ã¿ãŒãåãé€ããŸããã 代ããã«ãèŠæ±ããããšã³ãã£ãã£ãçŽæ¥åç §ããããã«ãã€ã³ã¿ãŒã匷å¶ããŸããã
ã³ãŒã
ããã©ãŒãã³ã¹ã®åäžã«å ããŠãPHP 7ã¯ã³ãŒãæ§é ã«å°ããªé©åœããããããŸããã
é¢æ°å®£èšã®ã¹ã«ã©ãŒ
PHP 7ããåã¯ããªããžã§ã¯ããã€ã³ã¿ãŒãã§ã€ã¹ãé åããŸãã¯åŒã³åºãå¯èœãªé¢æ°ã®ã¿ãé¢æ°ã®åŒæ°åã«ãªããŸããã äŸãšããŠæ¬¡ã®ã³ãŒããåãäžããŸãã
æããã«ããã®ãããªã¡ãœããã®äœ¿çšã¯ãå ¥ã£ãŠããåŒæ°ã®æ£ç¢ºããããããªãå Žåãå€ãã®åé¡ãçŽæããŸãã
åã¡ãœããã«åãã§ãã¯ãè¿œå ããããšã«å ããŠããã¡ã€ã³æåããã°ã©ãã³ã°ïŒDDDïŒã®ValueObjectã³ã³ã¹ãã©ã¯ãã䜿çšã§ããŸãã
PHP 7ã§ã¯ãstringãintãfloatãboolãªã©ã®ã¹ã«ã©ãŒãç°¡åã«æå®ã§ããŸãã ããã«ãæ»ãå€ã®ã¿ã€ããæå®ã§ããŸãã
å³æ Œã¢ãŒã
ãã ããäžèšã®æ§æãã³ãŒãã«è¿œå ããã ãã§ã¯ãæåŸ ããçµæãåŸãããªãå ŽåããããŸãã ããã¯ãPHP 7ãããã©ã«ãã§åŒ·å¶ã¢ãŒãã§åäœããéåžžã®åå€æãè¡ãããããã§ãã å³å¯ã¢ãŒãã匷å¶çã«ãªã³ã«ããŠããªãå Žåã¯ãäžèšã®ã¡ãœããã次ã®ããã«æžãæããããšãã§ããŸãã
æ®å¿µãªããã宣èšæ§é ïŒstrict_types = 1ïŒãPHPisNotDead.phpãã¡ã€ã«ã«è¿œå ããŠããå³æ Œã¢ãŒãã¯å«ãŸããŸããã 以äžã®äŸã®èª¬æã ã³ã¡ã³ãã¯æ»ãå€ã瀺ããŸãã
ãªããããèµ·ãã£ãŠããã®ã§ããïŒ PHPisNotDeadã¯ã©ã¹ã®ã¡ãœããã§ã®å³å¯ãªåæå®ã¯ãæ»ãå€ã«å¯ŸããŠã®ã¿æå¹ã§ãã
åŒæ°ã®å³å¯ãªåæå®ãæå¹ã«ããå¿ èŠãããå Žåã¯ãã¯ã©ã¹ã¡ãœãããåŒã³åºããããã¹ãŠã®ãã¡ã€ã«ã«strict_types宣èšãè¿œå ããå¿ èŠããããŸãã
ã¿ã€ãã®æå®ãšããã°ã©ã å®è¡ãžã®åœ±é¿ã®è©³çŽ°ã«ã€ããŠã¯ã ããã¥ã¡ã³ããåç §ããŠãã ããã ãã®ããã¥ã¡ã³ããèªãããšã§ãã³ãŒããå®è¡ããéã®é©ããé¿ããããšãã§ããŸãã
æªæ¥
ä»ã§ãPHP 7ã«åãæ¿ããããšã«æ±ºããŠããªãå Žåã¯ã ãµããŒããããŠããPHPã®ããŒãžã§ã³ã®ãªã¹ããã芧ãã ãã ã ããŒãžã§ã³5.6ã¯ã¢ã¯ãã£ããªãµããŒããåããªããªãã2018幎æ«ã«ã¯é倧ãªè匱æ§ã®ä¿®æ£ã§ãããå ¬éãããªããªããŸãã ããŒãžã§ã³7.0以éã®ã¢ã¯ãã£ããµããŒãã¯ç¶ç¶ãããŸãã
ææ°ã®PHPãã¥ãŒã¹ãšæ°ãããªãªãŒã¹ã®èšç»ãã楜ãã¿ã«ã æãèå³æ·±ãæçš¿ïŒ ãã¬ã³ããªãŒã¯ã©ã¹ ã ãžã§ããªãã¯åãé¢æ° ã PHP RFCã§ä»ã®èšèªéçºã®ææ¡ãèŠã€ããããšãã§ããŸãã
ãŸãšã
PHP 7ã¯å°è±¡çã§ããå¹çã®åäžã«å ããŠãéçºè ãããè¯ãã³ãŒããæžãã®ã«åœ¹ç«ã¡ãŸãã åãæ¿ãã決å®ããã®ã«åœ¹ç«ã€å°ããªããã¥ã¢ã«ãã¹ã±ããããŸããã
-PHP 7ã«ã¢ããã°ã¬ãŒãããå¿
èŠãããã®ã¯ãã€ã§ããïŒ
ãä»ãããã
ããŒã2. Avitoã®PHP 7
PHP 7.0ãžã®ç§»è¡ããã»ã¹
OLXãšåæ§ã«ããµãŒãã¹ãåŸã ã«PHP 7ã«ç¿»èš³ããŸããã ãŸããå°èŠæš¡ãªã¹ã¿ã³ãã¢ãã³ãµãŒãã¹ã転éããŠãã¹ãããçºçãããšã©ãŒãä¿®æ£ããŸããã 次ã«ããµã€ã管çãµãŒããŒã®é 次æŽæ°ã«é²ã¿ããã®åŸãæ®ãã®ãµãŒãã¹ãšãµã€ããPHP 7ã«ããŒã«ã¢ãŠãããŸããã
移è¡ã®é£ãã
åŸæ¹äºææ§ã®ãªãå€æŽã®ãªã¹ããèªã¿ãŸã ã ããããããã¯ãã¹ãŠã®ç æ°ãé²ãããšã¯ã§ããŸããã§ããã
å€ãã³ãŒãã«ã¯ãStringãšããã¯ã©ã¹ããããŸããã PHP 7ã¯ããäºçŽãããŠãããããã¯ã©ã¹åãšããŠãStringãã䜿çšã§ããŸããããšãããšã©ãŒãã¹ããŒããŸãã ã¯ã©ã¹ã®ååãå€æŽãããŸããã äºçŽèªã®ãªã¹ãã«æ³šæããŠãã ãã ã
PHP 7ã§ã¯ãSoapClientã®WSDLã¹ããŒã ã®ãã£ãã·ã¥ãã¡ã€ã«åœ¢åŒãå€æŽãããŸããã PHPã®ããŒãžã§ã³ã«å¿ããŠãã£ãã·ã¥ãç°ãªããã£ã¬ã¯ããªã«ä¿åããããã«èšå®ããããã€ã³ã¿ãŒããªã¿ãŒã®ããŒãžã§ã³ãå€æŽããåã«ãã£ãã·ã¥ãå®å šã«ã¯ãªã¢ããããšãã§ããŸãã
ç§ãã¡ãç©æ¥µçã«äœ¿çšããmongoæ¡åŒµã¢ãžã¥ãŒã«ã¯ãæ°ããPHPã§ã¯ãµããŒããããªããªããŸããã 代ããã«ãå ¬åŒã®MongoDB PHP Libraryã䜿çšãå§ããŸããã ã³ãŒãå šäœãèŠãŠãMongoCollection :: insertïŒïŒãMongoDB \ Collection :: insertOneïŒïŒã«ãMongoCollection :: removeïŒïŒãMongoDB \ Collection :: deleteManyïŒïŒã«ãããã«ãªã¹ããäžã«çœ®ãæããŸãã ã ããšãã°ãMongoDB \ BSON \ UTCDateTimeã®ä»£ããã«MongoDateãªã©ãæ°ããMongoDBãã©ã€ããŒããBSONãæäœããããã«ã¯ã©ã¹ã䜿çšãå§ããŸããã
çµæ
管çé åãåªããŠããŸãã
ãµã€ãã®ããã¯ãšã³ããæºè¶³ããŠããŸãã
PHP 7.1ãžã®ã¢ããã°ã¬ãŒã
PHP 7.1ã§ã¯ãããã€ãã®éåžžã«åªããé©æ°ãå°å ¥ãããŸãããæ»ãå€ã®voidåãå埩å¯èœãåä»ãæ»ãå€ã«nullãè¿ãæ©èœãå®æ°ã®ã¹ã³ãŒããªã©ã§ãã ããã«ãPHP 7.0ã®ç©æ¥µçãªãµããŒãæéã¯ä»å¹Žã®çµããã«çµäºããŸãã PHP 7.1ã«ã¢ããã°ã¬ãŒãããããšã«ããŸããã
é©ã
ããã«æŽæ°ãããšãåé¡ãçºçããŸããã 7.1ã®php-memcachedããã±ãŒãžã¯ãphp-igbinaryããã±ãŒãžããã«ããŸããã ããã«ãµãŒããŒã®1ã€ã«PHP 7.1ãã€ã³ã¹ããŒã«ãããšãä»ã®ãµãŒããŒãããšã©ãŒãæµãå§ãããigbinaryããšããåèªã衚瀺ãããŸããã
Memcacheã®å€ãããã®å人ãã·ãªã¢ã«åã®éãã§ããããœãŒã¹ã¯å°ãç°ãªããŸãã php-memcachedã¢ãžã¥ãŒã«ã¯ããã©ã«ãã§ãªã¹ãããæåã«å©çšå¯èœãªã·ãªã¢ã©ã€ã¶ãŒã䜿çšããããšãå€æããŸããïŒigbinaryïŒå¥ã®ã¢ãžã¥ãŒã«ïŒãmsgpackïŒå¥ã®ã¢ãžã¥ãŒã«ïŒãphpïŒå¥ã®ã¢ãžã¥ãŒã«ãå¿ èŠãšããªããåžžã«å©çšå¯èœïŒã ãããŠãigbinaryã§7.1ãã€ã³ã¹ããŒã«ãããµãŒããŒã¯ãigbinaryã«ãã£ãŠã·ãªã¢ã«åãããmemcacheã«ããŒã¿ãæžãå§ããŸããã ãŸããä»ã®ãµãŒããŒã§ã¯ããã®ã·ãªã¢ã©ã€ã¶ãŒã®ãµããŒãããªããæŽæ°ãããPHPã䜿çšããŠãµãŒããŒã«ãã£ãŠæžã蟌ãŸããããŒã¿ãèªã¿åãããšãã§ããŸããã§ããã åé¡ãç¹å®ããä»ã®ãã¹ãŠã®ãµãŒããŒã«igbinaryãã€ã³ã¹ããŒã«ãããšããšã©ãŒãåæ¢ããŸããã
ããšãã
PHPéçºè ã¯è¯ãã³ãŒã¹ãåã£ãŠããŸãã 圌ãã¯äŸ¿å©ãªããŒã«ãè¿œå ããèšèªã®éºç£ã«é¢é£ããæ¬ ç¹ãåãé€ããããã©ãŒãã³ã¹ã«ã€ããŠçå£ã«èããŠããŸãã
å ã»ã©ãAvitoã®ãµãŒãã¹ã¢ãŒããã¯ãã£ãžã®ç§»è¡ã«ã€ããŠèª¬æããŸããïŒ one ã two ïŒã ãã®ã¢ãŒããã¯ãã£ã«ãããä»»æã®èšèªã§èšè¿°ã§ããŸããã»ãšãã©ã®å ŽåãGoãŸãã¯Pythonã§æ°ãããµãŒãã¹ãèšè¿°ããŸãã ãã ããPHPãæŸæ£ããããšã«çåã®äœå°ã¯ãããŸããããµã€ãïŒã¢ããªã¹ïŒã®ã¡ã€ã³ããžãã¯ã¯ãŸã PHPã§ãããããŒã ã¯ããã䜿çšããæ¹æ³ãéåžžã«ããç¥ã£ãŠããŸãã ã€ã³ã¿ãŒããªã¿ãŒã®æ°ããããŒãžã§ã³ã¯ãã³ãŒããæ¹åãããã®å®è¡ãé«éåããŸãã
PHP 7以éã«åãæ¿ããçµéšãå ±æããŠãã ããããã®éçšã§åºäŒã£ãçºèŠãšã¬ãŒãã«ã€ããŠã話ãããŸãã