响应式图像教程

网页在不同尺寸的设备上,都有良好的显示效果,叫做”响应式设计”(responsive web design)。

响应式设计的网页图像,就是”响应式图像”(responsive image)。

响应式图像的解决方案有很多,JavaScript 和 CSS 都可以实现。本文介绍最简单的、语义性最好的 HTML 方法,浏览器原生支持。

一、问题的由来

我们知道,<img>标签用于插入网页图像,所有情况默认插入的都是同一张图像。


<img src="foo.jpg">

上面代码在桌面端和手机上,插入的都是图像文件foo.jpg

这种处理方法固然简单,但是有三大弊端。

(1)体积

一般来说,桌面端显示的是大尺寸的图像,文件体积较大。手机的屏幕较小,只需要小尺寸的图像,可以节省带宽,加速网页渲染。

(2)像素密度

桌面显示器一般是单倍像素密度,而手机的显示屏往往是多倍像素密度,即多个像素合成为一个像素,称为 Retina 屏幕。图像文件很可能在桌面端很清晰,放到手机上会有点模糊,因为像素扩充了。

(3)视觉风格

桌面显示器的面积较大,图像可以容纳更多细节。手机的屏幕较小,许多细节是看不清的,需要突出重点。

上面两张图片,下方的手机图片经过裁剪以后,更突出图像重点,明显效果更好。

二、像素密度的选择:srcset属性

为了解决上一节的这些问题,HTML 语言提供了一套完整的解决方案。首先,<img>标签引入了srcset属性。

srcset属性用来指定多张图像,适应不同像素密度的屏幕。它的值是一个逗号分隔的字符串,每个部分都是一张图像的 URL,后面接一个空格,然后是像素密度的描述符。请看下面的例子。


<img srcset="foo-320w.jpg,
             foo-480w.jpg 1.5x,
             foo-640w.jpg 2x"
     src="foo-640w.jpg">
 

上面代码中,srcset属性给出了三个图像 URL,适应三种不同的像素密度。

图像 URL 后面的像素密度描述符,格式是像素密度倍数 + 字母x1x表示单倍像素密度,可以省略。浏览器根据当前设备的像素密度,选择需要加载的图像。

如果srcset属性都不满足条件,那么就加载src属性指定的默认图像。

三、图像大小的选择:srcset属性 + sizes属性

像素密度的适配,只适合显示区域一样大小的图像。如果希望不同尺寸的屏幕,显示不同大小的图像,srcset属性就不够用了,必须搭配sizes属性。

第一步,srcset属性列出所有可用的图像。


<img srcset="foo-160.jpg 160w,
             foo-320.jpg 320w,
             foo-640.jpg 640w,
             foo-1280.jpg 1280w"
     src="foo-1280.jpg">

上面代码中,srcset属性列出四张可用的图像,每张图像的 URL 后面是一个空格,再加上宽度描述符。

宽度描述符就是图像原始的宽度,加上字符w。上例的四种图片的原始宽度分别为160像素、320像素、640像素和1280像素。

第二步,sizes属性列出不同设备的图像显示宽度。

sizes属性的值是一个逗号分隔的字符串,除了最后一部分,前面每个部分都是一个放在括号里面的媒体查询表达式,后面是一个空格,再加上图像的显示宽度。


<img srcset="foo-160.jpg 160w,
             foo-320.jpg 320w,
             foo-640.jpg 640w,
             foo-1280.jpg 1280w"
     sizes="(max-width: 440px) 100vw,
            (max-width: 900px) 33vw,
            254px"
     src="foo-1280.jpg">

上面代码中,sizes属性给出了三种屏幕条件,以及对应的图像显示宽度。宽度不超过440像素的设备,图像显示宽度为100%;宽度441像素到900像素的设备,图像显示宽度为33%;宽度900像素以上的设备,图像显示宽度为254px

第三步,浏览器根据当前设备的宽度,从sizes属性获得图像的显示宽度,然后从srcset属性找出最接近该宽度的图像,进行加载。

假定当前设备的屏幕宽度是480px,浏览器从sizes属性查询得到,图片的显示宽度是33vw(即33%),等于160pxsrcset属性里面,正好有宽度等于160px的图片,于是加载foo-160.jpg

注意,sizes属性必须与srcset属性搭配使用。单独使用sizes属性是无效的。

四、<picture>标签,<source>标签

上面两节分别解决了像素密度和屏幕大小的适配,但是如果要同时适配不同像素密度、不同大小的屏幕,应该怎么办呢?

这时,就要用到<picture>标签。它是一个容器标签,内部使用<source><img>,指定不同情况下加载的图像。


<picture>
  <source media="(max-width: 500px)" srcset="cat-vertical.jpg">
  <source media="(min-width: 501px)" srcset="cat-horizontal.jpg">
  <img src="cat.jpg" alt="cat">
</picture>

上面代码中,<picture>标签内部有两个<source>标签和一个<img>标签。

<source>标签的media属性给出媒体查询表达式,srcset属性就是<img>标签的srcset属性,给出加载的图像文件。sizes属性其实这里也可以用,但由于有了media属性,就没有必要了。

浏览器按照<source>标签出现的顺序,依次判断当前设备是否满足media属性的媒体查询表达式,如果满足就加载srcset属性指定的图片文件,并且不再执行后面的<source>标签和<img>标签。

<img>标签是默认情况下加载的图像,用来满足上面所有<source>都不匹配的情况。

上面例子中,设备宽度如果不超过500px,就加载竖屏的图像,否则加载横屏的图像。

下面给出一个例子,同时考虑屏幕尺寸和像素密度的适配。


<picture>
  <source srcset="homepage-person@desktop.png,
                  homepage-person@desktop-2x.png 2x"       
          media="(min-width: 990px)">
  <source srcset="homepage-person@tablet.png,
                  homepage-person@tablet-2x.png 2x" 
          media="(min-width: 750px)">
  <img srcset="homepage-person@mobile.png,
               homepage-person@mobile-2x.png 2x" 
       alt="Shopify Merchant, Corrine Anestopoulos">
</picture>

上面代码中,<source>标签的media属性给出屏幕尺寸的适配条件,每个条件都用srcset属性,再给出两种像素密度的图像 URL。

五、<source>标签的type属性

除了响应式图像,<picture>标签还可以用来选择不同格式的图像。比如,如果当前浏览器支持 Webp 格式,就加载这种格式的图像,否则加载 PNG 图像。


<picture>
  <source type="image/svg+xml" srcset="logo.xml">
  <source type="image/webp" srcset="logo.webp"> 
  <img src="logo.png" alt="ACME Corp">
</picture>

上面代码中,<source>标签的type属性给出图像的 MIME 类型,srcset是对应的图像 URL。

浏览器按照<source>标签出现的顺序,依次检查是否支持type属性指定的图像格式,如果支持就加载图像,并且不再检查后面的<source>标签了。上面例子中,图像加载优先顺序依次为 svg 格式、webp 格式和 png 格式。

六、参考链接

Responsive Images 101, Jason Grigsby Responsive images, MDN

PHP扩展编译安装

PHP扩展编译安装

# 下载
wget -c http://pecl.php.net/get/igbinary-3.0.1.tgz

# 解压
root@zheng:~# tar -zxvf igbinary-3.0.1.tgz
package.xml
igbinary-3.0.1/tests/igbinary_001.phpt
igbinary-3.0.1/tests/igbinary_002.phpt
igbinary-3.0.1/tests/igbinary_003.phpt
igbinary-3.0.1/tests/igbinary_004.phpt
igbinary-3.0.1/tests/igbinary_005.phpt
igbinary-3.0.1/tests/igbinary_006.phpt
igbinary-3.0.1/tests/igbinary_007.phpt
igbinary-3.0.1/tests/igbinary_008.phpt
igbinary-3.0.1/tests/igbinary_009.phpt
igbinary-3.0.1/tests/igbinary_009b.phpt
igbinary-3.0.1/tests/igbinary_010.phpt
igbinary-3.0.1/tests/igbinary_012.phpt
igbinary-3.0.1/tests/igbinary_013.phpt
igbinary-3.0.1/tests/igbinary_014.phpt
igbinary-3.0.1/tests/igbinary_015.phpt
igbinary-3.0.1/tests/igbinary_015b.phpt
igbinary-3.0.1/tests/igbinary_015c.phpt
igbinary-3.0.1/tests/igbinary_016.phpt
igbinary-3.0.1/tests/igbinary_017.phpt
igbinary-3.0.1/tests/igbinary_018.phpt
igbinary-3.0.1/tests/igbinary_019.phpt
igbinary-3.0.1/tests/igbinary_020.phpt
igbinary-3.0.1/tests/igbinary_021.phpt
igbinary-3.0.1/tests/igbinary_022.phpt
igbinary-3.0.1/tests/igbinary_023.phpt
igbinary-3.0.1/tests/igbinary_024.phpt
igbinary-3.0.1/tests/igbinary_025.phpt
igbinary-3.0.1/tests/igbinary_025b.phpt
igbinary-3.0.1/tests/igbinary_026.phpt
igbinary-3.0.1/tests/igbinary_026b.phpt
igbinary-3.0.1/tests/igbinary_027.phpt
igbinary-3.0.1/tests/igbinary_028.phpt
igbinary-3.0.1/tests/igbinary_029.phpt
igbinary-3.0.1/tests/igbinary_030_php72.phpt
igbinary-3.0.1/tests/igbinary_030_php7.phpt
igbinary-3.0.1/tests/igbinary_031.phpt
igbinary-3.0.1/tests/igbinary_032.phpt
igbinary-3.0.1/tests/igbinary_033.phpt
igbinary-3.0.1/tests/igbinary_034.phpt
igbinary-3.0.1/tests/igbinary_040.phpt
igbinary-3.0.1/tests/igbinary_041.phpt
igbinary-3.0.1/tests/igbinary_043.phpt
igbinary-3.0.1/tests/igbinary_044.phpt
igbinary-3.0.1/tests/igbinary_045b.phpt
igbinary-3.0.1/tests/igbinary_045c.phpt
igbinary-3.0.1/tests/igbinary_046.phpt
igbinary-3.0.1/tests/igbinary_046b.phpt
igbinary-3.0.1/tests/igbinary_046c.phpt
igbinary-3.0.1/tests/igbinary_046d.phpt
igbinary-3.0.1/tests/igbinary_047.phpt
igbinary-3.0.1/tests/igbinary_048.phpt
igbinary-3.0.1/tests/igbinary_048b.phpt
igbinary-3.0.1/tests/igbinary_049.phpt
igbinary-3.0.1/tests/igbinary_049b.phpt
igbinary-3.0.1/tests/igbinary_050.phpt
igbinary-3.0.1/tests/igbinary_051.phpt
igbinary-3.0.1/tests/igbinary_052.phpt
igbinary-3.0.1/tests/igbinary_053.phpt
igbinary-3.0.1/tests/igbinary_054.phpt
igbinary-3.0.1/tests/igbinary_055.phpt
igbinary-3.0.1/tests/igbinary_057.phpt
igbinary-3.0.1/tests/igbinary_058.phpt
igbinary-3.0.1/tests/igbinary_058b.phpt
igbinary-3.0.1/tests/igbinary_059.phpt
igbinary-3.0.1/tests/igbinary_060.phpt
igbinary-3.0.1/tests/igbinary_061.phpt
igbinary-3.0.1/tests/igbinary_062.phpt
igbinary-3.0.1/tests/igbinary_063_php72.phpt
igbinary-3.0.1/tests/igbinary_063_php7.phpt
igbinary-3.0.1/tests/igbinary_064.phpt
igbinary-3.0.1/tests/igbinary_065.phpt
igbinary-3.0.1/tests/igbinary_066.phpt
igbinary-3.0.1/tests/igbinary_067.phpt
igbinary-3.0.1/tests/igbinary_068.phpt
igbinary-3.0.1/tests/igbinary_069.phpt
igbinary-3.0.1/tests/igbinary_bug54662.phpt
igbinary-3.0.1/tests/igbinary_bug72134.phpt
igbinary-3.0.1/tests/igbinary_unserialize_v1_compatible.phpt
igbinary-3.0.1/config.m4
igbinary-3.0.1/config.w32
igbinary-3.0.1/igbinary.h
igbinary-3.0.1/php_igbinary.h
igbinary-3.0.1/src/php7/hash.h
igbinary-3.0.1/src/php7/hash_ptr.h
igbinary-3.0.1/src/php7/hash_si.c
igbinary-3.0.1/src/php7/hash_si_ptr.c
igbinary-3.0.1/src/php7/igbinary.c
igbinary-3.0.1/src/php7/igbinary.h
igbinary-3.0.1/src/php7/igbinary_macros.h
igbinary-3.0.1/src/php7/php_igbinary.h
igbinary-3.0.1/src/php7/ig_win32.h
igbinary-3.0.1/igbinary.php
igbinary-3.0.1/igbinary.php.ini
igbinary-3.0.1/tags.sh
igbinary-3.0.1/igbinary.spec
igbinary-3.0.1/COPYING
igbinary-3.0.1/CREDITS
igbinary-3.0.1/README.md
igbinary-3.0.1/NEWS
  • 1、在扩展解压包目录执行
root@zheng:~/igbinary-3.0.1# ll
total 72
drwxr-xr-x  4 root  root  4096 Jun 11 10:45 ./
drwxr-xr-x 10 root  root  4096 Jun 11 10:45 ../
-rw-rw-r--  1 zheng zheng 2876 Mar 21 07:51 config.m4
-rw-rw-r--  1 zheng zheng 1767 Mar 21 07:51 config.w32
-rw-r--r--  1 zheng zheng 1551 Mar 21 07:51 COPYING
-rw-rw-r--  1 zheng zheng  549 Mar 21 07:51 CREDITS
-rw-rw-r--  1 zheng zheng  235 Mar 21 07:51 igbinary.h
-rw-rw-r--  1 zheng zheng 3544 Mar 21 07:51 igbinary.php
-rw-r--r--  1 zheng zheng  136 Mar 21 07:51 igbinary.php.ini
-rw-r--r--  1 zheng zheng 1606 Mar 21 07:51 igbinary.spec
-rw-rw-r--  1 zheng zheng 4484 Mar 21 07:51 NEWS
-rw-rw-r--  1 zheng zheng  762 Mar 21 07:51 php_igbinary.h
-rw-rw-r--  1 zheng zheng 5863 Mar 21 07:51 README.md
drwxr-xr-x  3 root  root  4096 Jun 11 10:45 src/
-rwxr-xr-x  1 zheng zheng  211 Mar 21 07:51 tags.sh*
drwxr-xr-x  2 root  root  4096 Jun 11 10:45 tests/
root@zheng:~/igbinary-3.0.1# phpize
Configuring for:
PHP Api Version:         20151012
Zend Module Api No:      20151012
Zend Extension Api No:   320151012
root@zheng:~/igbinary-3.0.1# ll
total 1496
drwxr-xr-x  6 root  root    4096 Jun 11 10:47 ./
drwxr-xr-x 10 root  root    4096 Jun 11 10:45 ../
-rw-r--r--  1 root  root   82685 Jun 11 10:47 acinclude.m4
-rw-r--r--  1 root  root  414799 Jun 11 10:47 aclocal.m4
drwxr-xr-x  2 root  root    4096 Jun 11 10:47 autom4te.cache/
drwxr-xr-x  2 root  root    4096 Jun 11 10:47 build/
-rwxr-xr-x  1 root  root   43499 Jun 11 10:47 config.guess*
-rw-r--r--  1 root  root    2046 Jun 11 10:47 config.h.in
-rw-rw-r--  1 zheng zheng   2876 Mar 21 07:51 config.m4
-rwxr-xr-x  1 root  root   36144 Jun 11 10:47 config.sub*
-rwxr-xr-x  1 root  root  428873 Jun 11 10:47 configure*
-rw-r--r--  1 root  root    4698 Jun 11 10:47 configure.in
-rw-rw-r--  1 zheng zheng   1767 Mar 21 07:51 config.w32
-rw-r--r--  1 zheng zheng   1551 Mar 21 07:51 COPYING
-rw-rw-r--  1 zheng zheng    549 Mar 21 07:51 CREDITS
-rw-rw-r--  1 zheng zheng    235 Mar 21 07:51 igbinary.h
-rw-rw-r--  1 zheng zheng   3544 Mar 21 07:51 igbinary.php
-rw-r--r--  1 zheng zheng    136 Mar 21 07:51 igbinary.php.ini
-rw-r--r--  1 zheng zheng   1606 Mar 21 07:51 igbinary.spec
-rw-r--r--  1 root  root       0 Jun 11 10:47 install-sh
-rw-r--r--  1 root  root  324404 Jun 11 10:47 ltmain.sh
-rw-r--r--  1 root  root    7135 Jun 11 10:47 Makefile.global
-rw-r--r--  1 root  root       0 Jun 11 10:47 missing
-rw-r--r--  1 root  root       0 Jun 11 10:47 mkinstalldirs
-rw-rw-r--  1 zheng zheng   4484 Mar 21 07:51 NEWS
-rw-rw-r--  1 zheng zheng    762 Mar 21 07:51 php_igbinary.h
-rw-rw-r--  1 zheng zheng   5863 Mar 21 07:51 README.md
-rw-r--r--  1 root  root   83249 Jun 11 10:47 run-tests.php
drwxr-xr-x  3 root  root    4096 Jun 11 10:45 src/
-rwxr-xr-x  1 zheng zheng    211 Mar 21 07:51 tags.sh*
drwxr-xr-x  2 root  root    4096 Jun 11 10:45 tests/
root@zheng:~/igbinary-3.0.1#
  • 2、执行 ./configure –with-php-config=/usr/bin/php-config
root@zheng:~/igbinary-3.0.1# whereis php-config
php-config: /usr/bin/php-config /usr/bin/php-config7.0 /usr/share/man/man1/php-config.1.gz
root@zheng:~/igbinary-3.0.1# ./configure --with-php-config=/usr/bin/php-config
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
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether cc accepts -g... yes
checking for cc option to accept ISO C89... none needed
checking how to run the C preprocessor... cc -E
checking for icc... no
checking for suncc... no
checking whether cc understands -c and -o together... yes
checking for system library directory... lib
checking if compiler supports -R... no
checking if compiler supports -Wl,-rpath,... yes
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking target system type... x86_64-pc-linux-gnu
checking for PHP prefix... /usr
checking for PHP includes... -I/usr/include/php/20151012 -I/usr/include/php/20151012/main -I/usr/include/php/20151012/TSRM -I/usr/include/php/20151012/Zend -I/usr/include/php/20151012/ext -I/usr/include/php/20151012/ext/date/lib
checking for PHP extension directory... /usr/lib/php/20151012
checking for PHP installed headers prefix... /usr/include/php/20151012
checking if debug is enabled... no
checking if zts is enabled... no
checking for re2c... no
configure: WARNING: You will need re2c 0.13.4 or later if you want to regenerate PHP parsers.
checking for gawk... no
checking for nawk... nawk
checking if nawk is broken... no
checking whether to enable igbinary support... yes, shared
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking stdbool.h usability... yes
checking stdbool.h presence... yes
checking for stdbool.h... yes
checking stddef.h usability... yes
checking stddef.h presence... yes
checking for stddef.h... yes
checking for stdint.h... (cached) yes
checking PHP version... PHP 7
checking for APCu includes... not found
checking size of long... 8
checking compiler type... gcc
checking how to print strings... printf
checking for a sed that does not truncate output... (cached) /bin/sed
checking for fgrep... /bin/grep -F
checking for ld used by cc... /usr/bin/ld
checking if the linker (/usr/bin/ld) is GNU ld... yes
checking for BSD- or MS-compatible name lister (nm)... /usr/bin/nm -B
checking the name lister (/usr/bin/nm -B) interface... BSD nm
checking whether ln -s works... yes
checking the maximum length of command line arguments... 1572864
checking how to convert x86_64-pc-linux-gnu file names to x86_64-pc-linux-gnu format... func_convert_file_noop
checking how to convert x86_64-pc-linux-gnu file names to toolchain format... func_convert_file_noop
checking for /usr/bin/ld option to reload object files... -r
checking for objdump... objdump
checking how to recognize dependent libraries... pass_all
checking for dlltool... no
checking how to associate runtime and link libraries... printf %s\n
checking for ar... ar
checking for archiver @FILE support... @
checking for strip... strip
checking for ranlib... ranlib
checking for gawk... (cached) nawk
checking command to parse /usr/bin/nm -B output from cc object... ok
checking for sysroot... no
checking for a working dd... /bin/dd
checking how to truncate binary pipes... /bin/dd bs=4096 count=1
checking for mt... mt
checking if mt is a manifest tool... no
checking for dlfcn.h... yes
checking for objdir... .libs
checking if cc supports -fno-rtti -fno-exceptions... no
checking for cc option to produce PIC... -fPIC -DPIC
checking if cc PIC flag -fPIC -DPIC works... yes
checking if cc static flag -static works... yes
checking if cc supports -c -o file.o... yes
checking if cc supports -c -o file.o... (cached) yes
checking whether the cc linker (/usr/bin/ld -m elf_x86_64) supports shared libraries... yes
checking whether -lc should be explicitly linked in... no
checking dynamic linker characteristics... GNU/Linux ld.so
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... no
configure: creating ./config.status
config.status: creating config.h
config.status: executing libtool commands
root@zheng:~/igbinary-3.0.1# 
  • 3、编译 make&&make install (安装完成后在php安装目录下的扩展目录就会有相应的.so扩展文件。)
root@zheng:~/igbinary-3.0.1# make&&make insall
/bin/bash /home/zheng/igbinary-3.0.1/libtool --mode=compile cc -g -O2 -O2 -Wall -Wpointer-arith -Wcast-align -Wwrite-strings -Wswitch -finline-limit=10000 --param large-function-growth=10000 --param inline-unit-growth=10000 -I. -I/home/zheng/igbinary-3.0.1 -DPHP_ATOM_INC -I/home/zheng/igbinary-3.0.1/include -I/home/zheng/igbinary-3.0.1/main -I/home/zheng/igbinary-3.0.1 -I/usr/include/php/20151012 -I/usr/include/php/20151012/main -I/usr/include/php/20151012/TSRM -I/usr/include/php/20151012/Zend -I/usr/include/php/20151012/ext -I/usr/include/php/20151012/ext/date/lib  -DHAVE_CONFIG_H  -g -O2   -c /home/zheng/igbinary-3.0.1/src/php7/igbinary.c -o src/php7/igbinary.lo 
libtool: compile:  cc -g -O2 -O2 -Wall -Wpointer-arith -Wcast-align -Wwrite-strings -Wswitch -finline-limit=10000 --param large-function-growth=10000 --param inline-unit-growth=10000 -I. -I/home/zheng/igbinary-3.0.1 -DPHP_ATOM_INC -I/home/zheng/igbinary-3.0.1/include -I/home/zheng/igbinary-3.0.1/main -I/home/zheng/igbinary-3.0.1 -I/usr/include/php/20151012 -I/usr/include/php/20151012/main -I/usr/include/php/20151012/TSRM -I/usr/include/php/20151012/Zend -I/usr/include/php/20151012/ext -I/usr/include/php/20151012/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /home/zheng/igbinary-3.0.1/src/php7/igbinary.c  -fPIC -DPIC -o src/php7/.libs/igbinary.o
/bin/bash /home/zheng/igbinary-3.0.1/libtool --mode=compile cc -g -O2 -O2 -Wall -Wpointer-arith -Wcast-align -Wwrite-strings -Wswitch -finline-limit=10000 --param large-function-growth=10000 --param inline-unit-growth=10000 -I. -I/home/zheng/igbinary-3.0.1 -DPHP_ATOM_INC -I/home/zheng/igbinary-3.0.1/include -I/home/zheng/igbinary-3.0.1/main -I/home/zheng/igbinary-3.0.1 -I/usr/include/php/20151012 -I/usr/include/php/20151012/main -I/usr/include/php/20151012/TSRM -I/usr/include/php/20151012/Zend -I/usr/include/php/20151012/ext -I/usr/include/php/20151012/ext/date/lib  -DHAVE_CONFIG_H  -g -O2   -c /home/zheng/igbinary-3.0.1/src/php7/hash_si.c -o src/php7/hash_si.lo 
libtool: compile:  cc -g -O2 -O2 -Wall -Wpointer-arith -Wcast-align -Wwrite-strings -Wswitch -finline-limit=10000 --param large-function-growth=10000 --param inline-unit-growth=10000 -I. -I/home/zheng/igbinary-3.0.1 -DPHP_ATOM_INC -I/home/zheng/igbinary-3.0.1/include -I/home/zheng/igbinary-3.0.1/main -I/home/zheng/igbinary-3.0.1 -I/usr/include/php/20151012 -I/usr/include/php/20151012/main -I/usr/include/php/20151012/TSRM -I/usr/include/php/20151012/Zend -I/usr/include/php/20151012/ext -I/usr/include/php/20151012/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /home/zheng/igbinary-3.0.1/src/php7/hash_si.c  -fPIC -DPIC -o src/php7/.libs/hash_si.o
/bin/bash /home/zheng/igbinary-3.0.1/libtool --mode=compile cc -g -O2 -O2 -Wall -Wpointer-arith -Wcast-align -Wwrite-strings -Wswitch -finline-limit=10000 --param large-function-growth=10000 --param inline-unit-growth=10000 -I. -I/home/zheng/igbinary-3.0.1 -DPHP_ATOM_INC -I/home/zheng/igbinary-3.0.1/include -I/home/zheng/igbinary-3.0.1/main -I/home/zheng/igbinary-3.0.1 -I/usr/include/php/20151012 -I/usr/include/php/20151012/main -I/usr/include/php/20151012/TSRM -I/usr/include/php/20151012/Zend -I/usr/include/php/20151012/ext -I/usr/include/php/20151012/ext/date/lib  -DHAVE_CONFIG_H  -g -O2   -c /home/zheng/igbinary-3.0.1/src/php7/hash_si_ptr.c -o src/php7/hash_si_ptr.lo 
libtool: compile:  cc -g -O2 -O2 -Wall -Wpointer-arith -Wcast-align -Wwrite-strings -Wswitch -finline-limit=10000 --param large-function-growth=10000 --param inline-unit-growth=10000 -I. -I/home/zheng/igbinary-3.0.1 -DPHP_ATOM_INC -I/home/zheng/igbinary-3.0.1/include -I/home/zheng/igbinary-3.0.1/main -I/home/zheng/igbinary-3.0.1 -I/usr/include/php/20151012 -I/usr/include/php/20151012/main -I/usr/include/php/20151012/TSRM -I/usr/include/php/20151012/Zend -I/usr/include/php/20151012/ext -I/usr/include/php/20151012/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /home/zheng/igbinary-3.0.1/src/php7/hash_si_ptr.c  -fPIC -DPIC -o src/php7/.libs/hash_si_ptr.o
/bin/bash /home/zheng/igbinary-3.0.1/libtool --mode=link cc -DPHP_ATOM_INC -I/home/zheng/igbinary-3.0.1/include -I/home/zheng/igbinary-3.0.1/main -I/home/zheng/igbinary-3.0.1 -I/usr/include/php/20151012 -I/usr/include/php/20151012/main -I/usr/include/php/20151012/TSRM -I/usr/include/php/20151012/Zend -I/usr/include/php/20151012/ext -I/usr/include/php/20151012/ext/date/lib  -DHAVE_CONFIG_H  -g -O2   -o igbinary.la -export-dynamic -avoid-version -prefer-pic -module -rpath /home/zheng/igbinary-3.0.1/modules  src/php7/igbinary.lo src/php7/hash_si.lo src/php7/hash_si_ptr.lo 
libtool: link: cc -shared  -fPIC -DPIC  src/php7/.libs/igbinary.o src/php7/.libs/hash_si.o src/php7/.libs/hash_si_ptr.o    -g -O2   -Wl,-soname -Wl,igbinary.so -o .libs/igbinary.so
libtool: link: ( cd ".libs" && rm -f "igbinary.la" && ln -s "../igbinary.la" "igbinary.la" )
/bin/bash /home/zheng/igbinary-3.0.1/libtool --mode=install cp ./igbinary.la /home/zheng/igbinary-3.0.1/modules
libtool: install: cp ./.libs/igbinary.so /home/zheng/igbinary-3.0.1/modules/igbinary.so
libtool: install: cp ./.libs/igbinary.lai /home/zheng/igbinary-3.0.1/modules/igbinary.la
libtool: finish: PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin:/sbin" ldconfig -n /home/zheng/igbinary-3.0.1/modules
----------------------------------------------------------------------
Libraries have been installed in:
   /home/zheng/igbinary-3.0.1/modules

If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the '-LLIBDIR'
flag during linking and do at least one of the following:
   - add LIBDIR to the 'LD_LIBRARY_PATH' environment variable
     during execution
   - add LIBDIR to the 'LD_RUN_PATH' environment variable
     during linking
   - use the '-Wl,-rpath -Wl,LIBDIR' linker flag
   - have your system administrator add LIBDIR to '/etc/ld.so.conf'

See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------

Build complete.
Don't forget to run 'make test'.

Installing shared extensions:     /usr/lib/php/20151012/
Installing header files:          /usr/include/php/20151012/
root@zheng:~/igbinary-3.0.1# 
  • 4、配置支持php 修改php.ini 在最后一行添加以下内容 extension= 扩展文件名.so
[igbinary]
extension=igbinary.so
  • 5、重启服务
root@zheng:~/igbinary-3.0.1# systemctl restart php7.0-fpm.service