用c写php扩展实属无奈,要用到16进制数据进行异或,偏移;php操作实在麻烦,不得已,决定自己写一个简单的动态库进行调用;
环境:ubuntu10.0.4
1.下载php源代码
http://www.php.net/downloads.php
2.编译php源代码
在写扩展之前需要编译源代码,不然后期要用的phpize无法找到;
具体:
1.安装编译php所需要的库文件
sudo apt-get -y install libevent libevent-devel libxml2 libxml2-devel libmcrypt libmcrypt-devel libmcrypt libmcrypt-devel curl-devel
libpng-devel libtool-ltdl-devel
2.安装gcc
用于编译php yum -y install gcc
3.cd 到php源码所在目录
4.具体编译
1.tar zxvf php-5.3.10.tar.gz
2.cd php-5.3.10
3.配置 编译选项
./configure --prefix=/usr/local/php \
--enable-fpm \
--with-fpm-user=fpm \
--with-fpm-group=fpm \
--with-mysql=mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--without-pdo-sqlite \
--without-sqlite3 \
--without-sqlite \
--with-mysql-sock=/tmp/mysql.sock \
--with-curl \
--enable-mbstring \
--with-mhash \
--with-mcrypt \
--with-openssl \
--with-gd \
--enable-sockets \
--with-gettext \
--with-zlib \
--enable-zip \
--enable-soap \
--with-xmlrpc
不出意外,最后应该会看到以下结果:
+--------------------------------------------------------------------+
| License: |
| This software is subject to the PHP License, available in this |
| distribution in the file LICENSE. By continuing this installation |
| process, you are bound by the terms of this license agreement. |
| If you do not agree with the terms of this license, you must abort |
| the installation process at this point. |
+--------------------------------------------------------------------+
Thank you for using PHP.
编译常见问题
错误一:
configure: error: xml2-config not found. Please check your libxml2 installation.
而我已经安装过了libxml2,但是还是有这个提示:
解决办法:
# sudo apt-get install libxml2-dev
错误二:
configure: error: Please reinstall the BZip2 distribution
而我也已经安装了bzip2,网上找到得解决方案都是需要安装bzip2-dev,可是11.10里面没有这个库。
解决办法:在网上找到bzip2-1.0.5.tar.gz,解压,直接make ,sudo make install.(我使用的该源来自于http://ishare.iask.sina.com.cn/f/9769001.html)
错误三:
configure: error: Please reinstall the libcurl distribution -easy.h should be in <curl-dir>/include/curl/
解决办法:
# sudo apt-get install libcurl4-gnutls-dev
错误四:
configure: error: jpeglib.h not found.
解决办法:
# sudo apt-get install libjpeg-dev
错误五:
configure: error: png.h not found.
解决办法:
# sudo apt-get install libpng-dev
错误六:
configure: error: libXpm.(a|so) not found.
解决办法:
# sudo apt-get install libxpm-dev
错误七:
configure: error: freetype.h not found.
解决办法:
# sudo apt-get install libfreetype6-dev
NULL;
int arg_len, len;
char *strg;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &arg, &arg_len) == FAILURE) {
return;
}
len = spprintf(&strg, 0, "Congratulations! You have successfully modified ext/%.78s/config.m4. Module %.78s is now compiled into PHP.", "socketCheck", arg);
RETURN_STRINGL(strg, len, 0);
}
3.编译扩展模块
1.配置
./configure --with-php --with-php-config=/usr/local/php/bin/php-config
2.编译
make
3.安装
make install
4.扩展模块存放目录及配置生效
socketCheck.so 也已放到了php的扩展目录和(~/php-5.3.15/ext/socketCheck/modules)下
如果要是扩展模块可以调用,那么需要做两步操作:
1.配置文件添加扩展
打开php.ini 添加一行 extension=socketCheck.so
2.将socketCheck.so 拷贝到php默认的扩展目录,本机默认为(/usr/lib/php/modules)
3.重启apache
4.通过phpinfo()函数检查扩展是否加载成功;
或者 /usr/local/php/bin/php -m|grep socketCheck查看是否有 socketCheck.so
|