函数计算 php runtime 编译非内置的扩展

php runtime 使用FAQ

问题

函数计算 php runtime 中的 php 版本为 7.2.7,php runtime 已经内置了较多的扩展,具体如下:

"Core", "date", "libxml", "openssl", "pcre", "zlib", "curl","filter", "hash", "readline", "Reflection", 
"SPL", "session","xml", "standard", "mysqlnd", "bcmath", "bz2", "calendar","ctype", "dom", "mbstring", 
"fileinfo", "ftp", "gettext", "gmp", "iconv","imagick", "json", "exif", "mysqli", "pcntl", "PDO", 
"pdo_mysql","Phar", "posix", "protobuf", "redis", "shmop", "SimpleXML", "soap","sockets", "sysvmsg", "zip", "memcached",
"sysvsem", "sysvshm", "tokenizer", "xmlreader","xmlrpc", "xmlwriter", "Zend OPcache", "xdebug",

但是还有用户具有其他扩展的需求,比如用户有对 php-gd 扩展的需求, 在本文中,以 php-gd 扩展为例, 我们讲解如果利用fcli 工具编译其他没有内置的扩展,php相关的扩展如下: php-ext

文章最后章节提供了编译好的扩展下载.

操作方法

简单,不需要额外底层库, 直接可以安装成功

~ tmp # fcli shell
Welcome to the function compute world. Have fun!
>>> sbox -t php7.2 -d code
Entering the container. Your code is in the /code direcotry.
Unable to find image 'aliyunfc/runtime-php7.2:build' locally
build: Pulling from aliyunfc/runtime-php7.2
...

root@c83d77cb373d:/code# docker-php-ext-install gd
Configuring for:
PHP Api Version:         20170718
Zend Module Api No:      20170718
Zend Extension Api No:   320170718
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for a sed that does not truncate output... /bin/sed
checking for cc... cc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
....

Installing shared extensions:     /usr/local/lib/php/extensions/no-debug-non-zts-20170718/
Installing header files:          /usr/local/include/php/
find . -name \*.gcno -o -name \*.gcda | xargs rm -f
find . -name \*.lo -o -name \*.o | xargs rm -f
find . -name \*.la -o -name \*.a | xargs rm -f
find . -name \*.so | xargs rm -f
find . -name .libs -a -type d|xargs rm -rf
rm -f libphp.la       modules/* libs/*
root@c83d77cb373d:/code# ls /usr/local/lib/php/extensions/no-debug-non-zts-20170718/
bcmath.so    dom.so      gd.so       iconv.so       mysqli.so   pdo_mysql.so  redis.so       soap.so     sysvshm.so    xmlrpc.so
bz2.so         exif.so      gettext.so  imagick.so   opcache.so  phar.so         session.so    sockets.so  tokenizer.so  xmlwriter.so
calendar.so  fileinfo.so  gmp.so      json.so       pcntl.so    posix.so      shmop.so       sysvmsg.so  xdebug.so
ctype.so     ftp.so      hash.so     mbstring.so  pdo.so      protobuf.so   simplexml.so  sysvsem.so  xmlreader.so
root@c83d77cb373d:/code# cp /usr/local/lib/php/extensions/no-debug-non-zts-20170718/gd.so ./

最后从sbox 命令中关联的code目录把 gd.so 提取出来, 然后参考:
php runtime 使用自定义扩展

复杂,需要额外底层库

root@fb4e2bc65410:/code# apt-get update
root@fb4e2bc65410:/code# apt-get install libsqlite3-dev
root@fb4e2bc65410:/code# docker-php-ext-install pdo_sqlite
root@fb4e2bc65410:/code# find / -name "pdo_sqlite.so"
/usr/local/lib/php/extensions/no-debug-non-zts-20170718/pdo_sqlite.so
root@fb4e2bc65410:/code# find / -name "*libsqlite3*"
/usr/lib/x86_64-linux-gnu/libsqlite3.so
/usr/lib/x86_64-linux-gnu/libsqlite3.la
/usr/lib/x86_64-linux-gnu/libsqlite3.a
/usr/lib/x86_64-linux-gnu/libsqlite3.so.0
/usr/lib/x86_64-linux-gnu/libsqlite3.so.0.8.6
...
root@fb4e2bc65410:/code# mkdir lib
root@fb4e2bc65410:/code# cp /usr/lib/x86_64-linux-gnu/libsqlite3* ./lib
root@fb4e2bc65410:/code# ls lib
libsqlite3.a  libsqlite3.la  libsqlite3.so  libsqlite3.so.0  libsqlite3.so.0.8.6
root@fb4e2bc65410:/code# mkdir extension
root@fb4e2bc65410:/code# cp /usr/local/lib/php/extensions/no-debug-non-zts-20170718/pdo_sqlite.so ./extension/
root@fb4e2bc65410:/code# touch index.php
root@fb4e2bc65410:/code# ls -ll
total 0
drwxr-xr-x 3 root root  96 May 15 10:46 extension
-rw-r--r-- 1 root root   0 May 15 10:46 index.php
drwxr-xr-x 7 root root 224 May 15 10:45 lib

扩展下载

php-gd download

pgsql-demo

pdo_sqlite

pdo_sqlsrv

swoole

上一篇:C++ runtime sample


下一篇:数据分页时每页首条记录索引如何计算