AWS Lambda에서 Phalcon 사용 가능

7130 단어 PHPPhalconlambda
AWS Lambda에서 Phalcon과 다른 php extensions를 사용하는 방법에 대한 소개
수요가 있는지 모르겠어요.
AWS Lambda에서 PHP 사용 방법에 대해서는 참조여기

phalcon 컴파일


AWS Lambda는 아마존 리눅스에서 실행되기 때문에 리눅스 환경에서 컴파일됩니다.
기본적으로 공식 수첩 그러면 되지만 설치 스크립트는 설치할 때까지 쓰기 때문에 구축용 환경에서 phalcon을 설치하지 않으려면 고쳐야 합니다.
build-only.patch
diff --git build/install build/install
index 60f5e29..29f4d85 100755
--- build/install
+++ build/install
@@ -61,4 +61,4 @@ if [ -f Makefile ]; then
 fi

 #Perform the compilation
-phpize && ./configure --enable-phalcon && make && make install && echo -e "\nThanks for compiling Phalcon!\nBuild succeed: Please restart your web server to complete the installation"
+phpize && ./configure --enable-phalcon && make && echo -e "\nThanks for compiling Phalcon!\nBuild succeed"
공유 라이브러리 파일은 build/64bits/modules/phalcon.so 로 생성됩니다.

파일 구성 예


file-tree
├── index.js
├── script.sh
├── app
│   └── index.php
└── php
    ├── ext
    │   └── phalcon.so #phalcon extension
    ├── php            #php cli
    └── php.ini

각 파일에 대한 간략한 설명


index.js
exports.handler = function(event, context) {
  var exec = require('child_process').exec;
  var uri_path = "undefined" == typeof event.uri_path
                 ? '' : event.uri_path;
  exec('sh script.sh ' + uri_path, function (error, stdout, stderr) {
    if(stdout){
      console.log('stdout: ' + stdout);
    }
    if(stderr){
      console.log('stderr: ' + stderr);
    }
    if (error !== null) {
      console.log('Exec error: ' + error);
    }
    context.succeed(stdout);
  });
};
↑index.js는 AWS Lambda를 시작할 때 처음 읽은 파일입니다.여기서부터 스크립트.sh를 시작합니다.
script.sh
#!/bin/sh
./php/php -S localhost:8080 -t ./app &
until curl http://localhost:8080/$1
do
    :
done
kill $!
↑ php의built-in 서버를 시작하고curl 명령으로 요청을 던진다.
built-in 서버가 상승하기 전에curl 명령이 이동할 수 있기 때문에, 응답을 정상적으로 받을 때까지 until을 사용하여 다시 시도합니다.
app/index.php
<?php
phpinfo();
↑script.sh에서 시작된built-in 서버에서 인용한 파일입니다.phalcon을 읽었는지 확인하기 위해 phpinfo () 를 출력합니다.
php.ini
date.timezone="Asia/Tokyo"
extension_dir="/var/task/php/ext"
extension=phalcon.so
↑ extention으로 사용되는 phalcon의 설정을 읽는 데 사용됩니다.
php-configure-options
./configure \\
--prefix=/var/task/php \\
--disable-all \\
&& make
↑ php의 configure 옵션.
php 업로드.ini 설정 prefix 참조.

AWS Lambda에 업로드

zip -r phalcon.zip app index.js php script.sh파일을 zip에 모아 업로드합니다.
이번에 zip 파일이 3MB 정도 되어서 AWS Lambda의 웹 콘솔에서 업로드되었습니다.
다른 확장 또는 PHP를 사용하는 응용 프로그램이 10MB 이상인 경우 S3에 잠시 업로드해야 합니다.

결과


API 게이트웨이를 통해 phpinfo 출력에 액세스하고 체크했습니다.
phalcon을 extension으로 읽습니다.

API Gateway를 통해 AWS Lambda가 HTML을 내보내는 방법에 대해서는 여기 을 참조하십시오.

총결산


php.ini를 참조하기 위해서는 php의configure 옵션을 설정하는 것이 중요합니다.
같은 설정을 하면 다른 extension도 사용할 수 있습니다.

좋은 웹페이지 즐겨찾기