ãã®è¨äºã¯AutoScale Advent Calendar 2018 - Qiitaã®11æ¥ç®ã§ãã
2018å¹´7æ12æ¥ãGoogle App Engine(GAE) ãã¤ãã« PHP 7.2 ã«å¯¾å¿ãã¾ããï¼
SocialDogããAutoScaleã®ã¦ã§ããµã¤ããªã©ãã¡ãã£ã¨åçãªè¦ç´ ããã£ã¦ããã£ãã·ã¥ãå¹ããããªãã¼ã¸ã§ã¯ãGoogle App Engine ãç©æ¥µçã«æ´»ç¨ãã¦ãã¾ããã*1
ãã¾ã¾ã§GAEã§ã¯PHP5.5ãã対å¿ãã¦ããªãã£ãã®ã§ãPHP7.2 ã¸ã®å¯¾å¿ã§ä¸æ°ã«æªæ¥ã«ããæããããã¾ãã ã¡ãªã¿ã«PHP5.6, 5.7, 7.1 ãªã©éã®ãã¼ã¸ã§ã³ã«ã¯å¯¾å¿ãã¦ãã¾ãããGAE ã§PHPã使ãå ´åã¯ãPHP5.5ã7.2ã®2æã§ãã
ãã®è¨äºã§ã¯æ¢åã®PHP5.5ã®ããã¸ã§ã¯ããPHP7.2ã§ä½¿ãããã®è¨å®ãè¦ã¦ã¿ããã¨æãã¾ãã
- Google App Engine PHP5.5 ã¨PHP 7.2 ã®ä¸»ãªéã
- Google App Engine PHP5.5 ã¨PHP 7.2 ã§å¤ãããªãç¹
- PHP 7.2 ã«ç§»è¡ã§ããªãç°å¢
- app.yaml ã®ä»æ§å¤æ´
- æ¡å¼µæ©è½ã®è¿½å
- ãã¼ã«ã«ã§ã®ãã¹ã
- ãããã¤
- ã¾ã¨ã
- åèè³æ
Google App Engine PHP5.5 ã¨PHP 7.2 ã®ä¸»ãªéã
- èªç±åº¦ã大å¹
ã¢ããï¼
- ã©ã³ã¿ã¤ã ç°å¢ã第ä¸ä¸ä»£ãã第äºä¸ä»£ï¼gVisor ãã¼ã¹ã®ã³ã³ãããµã³ãããã¯ã¹ç°å¢ï¼ã«ãªã£ã
- æ¡å¼µã®å°å ¥ãå¯è½ã«ããããç°¡å
- URLåå¾é¢æ°ã使ããªãã¦ãå¤é¨ãããã¯ã¼ã¯ã¢ã¯ã»ã¹ãå¯è½ã«
- ãã¡ã¤ã«ã·ã¹ãã ã¸ã®ã¢ã¯ã»ã¹æ¨©ãä»ä¸ã
/tmp
ã«ã¢ã¯ã»ã¹å¯è½ã«
- app.yaml ã®ä»æ§å¤æ´
- Compose ã®èªåã¤ã³ã¹ãã¼ã«ï¼
composer.json
ãã«ã¼ãã«ç½®ãã ãã§èªåçã«ãããã¤å¯è½ã«ï¼- .gitigonore ãã¦ããå ´åã¯ç¡è¦ããããããªã®ã§é常ã¯ç¹æ®µã®å¯¾å¿ä¸è¦ï¼
- App Engine ç¬èªã®æ©è½ã¸ã®ã¢ã¯ã»ã¹ã®å»æ¢
- GAE 㯠Google Cloud Platform ã¨ãªãåãããããµã¼ãã¹ã§ããã¨ããæ´å²ççµç·¯ããæ®ã£ã¦ãããGAEã®ä¸ã® Memcached ,BlobStore, Mail, Taskãã¥ã¼, æ¤ç´¢ããã°ãµã¼ãã¹ãªã©ãå»æ¢ã«ãªãã¾ãããä»å¾ã¯Cloud Storage ã Cluod Datastore ãªã©ã®GCPã®ä»ã®ãµã¼ãã¹ã使ã£ã¦ã¨ãããã¨ã®ããã§ãã
- ãã ããã¡ã¼ã«éä¿¡*2ããMemcache*3ãæ¤ç´¢*4ãªã©GCPã«ã¯ãªãã®ã«å»æ¢ããã¦ããæ©è½ãããã®ã§ããããã«ä¾åãã¦ããå ´åã¯ãPHP7.2ã¸ã®ä»¥éã¯ããªã大å¤ããã§ãã
- ãã¼ã«ã«ã§ã®ãã¹ãã³ãã³ã
dev_appserver.py
ã®å»æ¢
Google App Engine PHP5.5 ã¨PHP 7.2 ã§å¤ãããªãç¹
- ç¡ææ ã®å®ç¾©
- SLAï¼ãã ãPHP7.2 ã¯ã¾ã ãã¼ã¿ãªã®ã§æ£å¼çã«ãªã£ããå¤ãããªãã¯ãï¼
- ãããã¤ã³ãã³ãï¼
gcloud app deploy
ï¼
PHP 7.2 ã«ç§»è¡ã§ããªãç°å¢
App Engine ç¬èªã®æ©è½ã使ã£ã¦ããå ´åã¯ãPHP7.2ç°å¢ã¸ã®ç§»è¡ã¯ããªãå°é£ããã§ãããã§ã«åãã¦ããããã¸ã§ã¯ããªã®ã§ããã°ä»ã¯è«¦ãã¦ãå½è©²ã®æ©è½ã GCP ã§ãã«ããã¼ã¸ããªãµã¼ãã¹ãåºãã¾ã§å¾ ã¤ãã¨ããã®ããããã¨æãã¾ãã
app.yaml ã®ä»æ§å¤æ´
以ä¸ã®ãã©ã¡ã¼ã¿ã¯å»æ¢äºå®ãªã®ã§åé¤ãã¾ãã
threadsafe
, api_version
, application_readable
, builtins
, libraries
runtimeãPHP7.2ã«ãã¾ãã
runtime: php72
handlers
ã®åã® script
㯠script: auto
ã®ã¿è¨å®ã§ããããã«ãªãã¾ããã
çã®PHPãç´æ¥ç½®ãããããã¬ã¼ã ã¯ã¼ã¯ã®ã¨ã³ããªã¼ãã¤ã³ãã®ãã¡ã¤ã«ãã²ã¨ã¤ã ãæå®ãã¦ã«ã¼ãã£ã³ã°ããã®ãæ®éãªã®ã§ããã®ä¿®æ£ã¯ç´å¾æãããã¾ãã
以ä¸ã®ããã«æå®ããã¨ã/images
以ä¸ã¯ç´æ¥å¼ã³ã¤ã¤ããã以å¤ã¯ index.php
ãpublic/index.php
ãåæã«å¼ãã§ããã¾ãã
handlers: - url: /images static_dir: static/images - url: /.* script: auto
詳細ã¯ä»¥ä¸ãåç §:
æ¡å¼µæ©è½ã®è¿½å
æ¡å¼µæ©è½ã追å ãããå ´åã¯ãphp.ini
ãããã¦ã以ä¸ã®ããã«ãã¾ãã
extension=memcached.so extension=grpc.so extension=protobuf.so extension=mongodb.so extension=imagick.so extension=opencensus.so extension=redis.so extension=stackdriver_debugger.so
ãã¼ã«ã«ã§ã®ãã¹ã
dev_appserver.py
ãå»æ¢ãããã®ã§ã以ä¸ã®ã³ãã³ãã§ãã¹ããã¾ãã
$ php -S localhost:8080
ãããã¤
ãã¾ã¾ã§ã©ããã§ãã
$ gcloud app deploy --project [Project ID]
ã¾ã¨ã
PHP 7.2 ã§ã¯ãPHP5.5 ã¨æ¯ã¹ã¦ããªãèªç±åº¦ãé«ããªã£ã¦ãã¾ãã
ç¹ã«æ¡å¼µãå ¥ãããã or äºãå ¥ã£ã¦ããã¨ããã®ã¨ããã¡ã¤ã«ã·ã¹ãã ã«ã¢ã¯ã»ã¹ã§ãããããã¯ãããæè»ã« GAE ãæ´»ç¨ã§ããããã«ãã¦ããããã§ãã
ä¸æ¹ã§ãæ¢åã® GAE ã®ã¿ã®æ©è½ã使ããªããªã£ã¦ããã®ã§ãæ¢åã® PHP5.5 ã§ãããã使ã£ã¦ããå ´åã¯ç§»è¡ã¯ããªãé£ãããªãããã§ããç¹ã« Memcached ã使ã£ã¦ããå ´åã¯ããªããã¤ãã®ã§ã¯ãªãã§ããããã
PHP5.5 ãã PHP7.2 ã¨ããªããã¼ã¸ã§ã³ã¢ãããã¦ããã®ã§ãããã©ã¼ãã³ã¹é¢ã§ãæ¹åãããã§ãï¼æªæ¤è¨¼ï¼ã
åèè³æ
- App Engine Standard Environment Runtimes  | App Engine Documentation  | Google Cloud
- PHP 7.2 Runtime Environment  | App Engine standard environment for PHP 7.2 docs  | Google Cloud
*1:SocialDog æ¬ä½ã¯å¥ã®ãµããã¡ã¤ã³ã§GCEã§ãããã¦ãã¾ã
*2:ããã¥ã¡ã³ãã§ã¯SendGridãMailjetãããããããã¦ãã
*3:Radis Labs Cloud ãããããããã¦ãã
*4:ããã¥ã¡ã³ãã«ã¯ ElasticSearch on GCE ã使ã£ããã©ãï¼ã¨æ¸ãã¦ããããPaaS ã¨ã¯ãªãã ã£ãã®ãï½