原创

关于php创建扩展的一个坑:找不到skeleton

温馨提示:
本文最后更新于 2019年07月06日,已超过 1,756 天没有更新。若文章内的图片失效(无法正常加载),请留言反馈或直接联系我

在前几天,我突然想研究树莓派的php io扩展,然后开始看自己之前的扩展开发教程:http://www.php20.cn/article/sw/%E6%89%A9%E5%B1%95/177

随便下载了一个php7.1的版本,cd 进入ext文件:

pi@raspberrypi:~/php-src-php-7.1.29 $ cd ext/
pi@raspberrypi:~/php-src-php-7.1.29/ext $ ls
bcmath    com_dotnet  date  enchant   ext_skel_win32.php  ftp      gmp    imap       json    mbstring
bz2       ctype       dba   exif      fileinfo            gd       hash   interbase  ldap
calendar  curl        dom   ext_skel  filter              gettext  iconv  intl       libxml
pi@raspberrypi:~/php-src-php-7.1.29/ext $

才发现,原来只有php7.3的某一个版本,才是用的 ext_skel.php   文件生成,在之前的版本,都是shell

仙士可博客

其实都差不多啦,然后我开始了正常的生成操作:

pi@raspberrypi:~/php-src-php-7.1.29/ext $ ./ext_skel --extname=phpPi
./ext_skel: 1: cd: can't cd to skeleton
Creating directory phpPi
Creating basic files: config.m4 config.w32 .gitignore phpPi.c./ext_skel: 247: ./ext_skel: cannot open /skeleton.c: No such file
 php_phpPi.h./ext_skel: 265: ./ext_skel: cannot open /php_skeleton.h: No such file
 CREDITS./ext_skel: 269: ./ext_skel: cannot open /CREDITS: No such file
 EXPERIMENTAL./ext_skel: 273: ./ext_skel: cannot open /EXPERIMENTAL: No such file
 tests/001.phpt./ext_skel: 278: ./ext_skel: cannot open /tests/001.phpt: No such file
 phpPi.php./ext_skel: 282: ./ext_skel: cannot open /skeleton.php: No such file
 [done].

To use your new extension, you will have to execute the following steps:

1.  $ cd ..
2.  $ vi ext/phpPi/config.m4
3.  $ ./buildconf
4.  $ ./configure --[with|enable]-phpPi
5.  $ make
6.  $ ./sapi/cli/php -f ext/phpPi/phpPi.php
7.  $ vi ext/phpPi/phpPi.c
8.  $ make

Repeat steps 3-6 until you are satisfied with ext/phpPi/config.m4 and
step 6 confirms that your module is compiled into PHP. Then, start writing
code and repeat the last two steps as often as necessary.

pi@raspberrypi:~/php-src-php-7.1.29/ext $

./ext_skel: 1: cd: can't cd to skeleton 错误是什么鬼???

百度了一晚上,一直没找到原因,后来我换成了php7.3版本

pi@raspberrypi:~/php-src-php-7.3.3/ext $ php ext_skel.php 
Error: No extension name passed, use "--ext <name>"
pi@raspberrypi:~/php-src-php-7.3.3/ext $ php ext_skel.php --ext phpPi
Error: The skeleton directory was not found
pi@raspberrypi:~/php-src-php-7.3.3/ext $

同样报错

Error: The skeleton directory was not found

那 skeleton是什么呢?

我查了很久很久,后来才发现,在php-src源码中,是有skeleton这个目录的,在ext目录下,还有着很多很多的扩展,而我解压的文件却没有显示:

仙士可博客

仙士可博客

很明显,我下载的文件有问题,我用的是wget方式下载,后来我登录其他服务器,使用其他服务器下载下来,才发现了区别:

仙士可博客

仙士可博客

很明显了,下载的时候,可能因为网络问题,导致文件缺失。并且解压的时候有提示,只是我那时候根本不知道:

仙士可博客

gzip: stdin: unexpected end of file

tar: 归档文件中异常的 EOF

tar: 归档文件中异常的 EOF

tar: Error is not recoverable: exiting now

这下终于找到了原因,通过解压完整版,开始生成扩展:

仙士可博客

成功生成扩展文件,可以愉快的写代码了

正文到此结束
本文目录