linux下 C語言對 php 擴展
更新時間:2008年12月14日 17:57:40 作者:
linux C語言對 php 擴展的設(shè)置技巧
一,搭建php環(huán)境
下載php 5.2.6 源碼 并解壓
編譯安裝,搭建php環(huán)境
二,創(chuàng)建擴展項目
進入源碼目錄
cd php5.2.6/ext/
./ext_skel --extname=my_ext
創(chuàng)建名字為my_ext的項目,最終會生成my_ext.so
三,更改配置和程序
$ vi ext/my_ext/config.m4
根據(jù)你自己的選擇將
dnl PHP_ARG_WITH(my_ext, for my_ext support,
dnl Make sure that the comment is aligned:
dnl [ --with-my_ext Include my_ext support])
修改成
PHP_ARG_WITH(my_ext, for my_ext support,
Make sure that the comment is aligned:
[ --with-my_ext Include my_ext support])
或者將
dnl PHP_ARG_ENABLE(my_ext, whether to enable my_ext support,
dnl Make sure that the comment is aligned:
dnl [ --enable-my_ext Enable my_ext support])
修改成
PHP_ARG_ENABLE(my_ext, whether to enable my_ext support,
Make sure that the comment is aligned:
[ --enable-my_ext Enable my_ext support])
$ vi ext/my_ext/php_my_ext.h
將
PHP_FUNCTION(confirm_my_ext_compiled); /* For testing, remove later. */
更改為
PHP_FUNCTION(say_hello);
$ vi ext/my_ext/my_ext.c
將
zend_function_entry php5cpp_functions[] = {
PHP_FE(confirm_my_ext_compiled, NULL) /* For testing, remove later. */
{NULL, NULL, NULL} /* Must be the last line in php5cpp_functions[] */
};
更改為
zend_function_entry php5cpp_functions[] = {
PHP_FE(say_hello, NULL)
{NULL, NULL, NULL} /* Must be the last line in php5cpp_functions[] */
};
在最后添加:
PHP_FUNCTION(say_hello)
{
zend_printf("hello world\n");
}
四,編譯
$ cd my_ext
$ /usr/local/php/bin/phpize
ps: 如果出現(xiàn):Cannot find autoconf.……的錯誤信息,則需要安裝 autoconf (安裝過程略)
$ ./configure --with-php-config=/usr/local/php/bin/php-config
$ make
這時會編譯出 my_ext/modules/my_ext.so
五,配置php.ini
將my_ext.so放入/usr/local/php/ext/目錄
$ vi php.ini
修改添加如下:
extension_dir = '/usr/local/php/ext/'
extension=my_ext.so
六,測試
$ vi test.php
<?php
say_hello();
?>
$ /usr/local/php/bin/php test.php
hello world.
則大功告成
ps:如有問題請留言,大家共同探討
下載php 5.2.6 源碼 并解壓
編譯安裝,搭建php環(huán)境
二,創(chuàng)建擴展項目
進入源碼目錄
cd php5.2.6/ext/
./ext_skel --extname=my_ext
創(chuàng)建名字為my_ext的項目,最終會生成my_ext.so
三,更改配置和程序
$ vi ext/my_ext/config.m4
根據(jù)你自己的選擇將
dnl PHP_ARG_WITH(my_ext, for my_ext support,
dnl Make sure that the comment is aligned:
dnl [ --with-my_ext Include my_ext support])
修改成
PHP_ARG_WITH(my_ext, for my_ext support,
Make sure that the comment is aligned:
[ --with-my_ext Include my_ext support])
或者將
dnl PHP_ARG_ENABLE(my_ext, whether to enable my_ext support,
dnl Make sure that the comment is aligned:
dnl [ --enable-my_ext Enable my_ext support])
修改成
PHP_ARG_ENABLE(my_ext, whether to enable my_ext support,
Make sure that the comment is aligned:
[ --enable-my_ext Enable my_ext support])
$ vi ext/my_ext/php_my_ext.h
將
PHP_FUNCTION(confirm_my_ext_compiled); /* For testing, remove later. */
更改為
PHP_FUNCTION(say_hello);
$ vi ext/my_ext/my_ext.c
將
zend_function_entry php5cpp_functions[] = {
PHP_FE(confirm_my_ext_compiled, NULL) /* For testing, remove later. */
{NULL, NULL, NULL} /* Must be the last line in php5cpp_functions[] */
};
更改為
zend_function_entry php5cpp_functions[] = {
PHP_FE(say_hello, NULL)
{NULL, NULL, NULL} /* Must be the last line in php5cpp_functions[] */
};
在最后添加:
PHP_FUNCTION(say_hello)
{
zend_printf("hello world\n");
}
四,編譯
$ cd my_ext
$ /usr/local/php/bin/phpize
ps: 如果出現(xiàn):Cannot find autoconf.……的錯誤信息,則需要安裝 autoconf (安裝過程略)
$ ./configure --with-php-config=/usr/local/php/bin/php-config
$ make
這時會編譯出 my_ext/modules/my_ext.so
五,配置php.ini
將my_ext.so放入/usr/local/php/ext/目錄
$ vi php.ini
修改添加如下:
extension_dir = '/usr/local/php/ext/'
extension=my_ext.so
六,測試
$ vi test.php
<?php
say_hello();
?>
$ /usr/local/php/bin/php test.php
hello world.
則大功告成
ps:如有問題請留言,大家共同探討
您可能感興趣的文章:
- C語言編寫Linux守護進程實例
- linux安裝mysql和使用c語言操作數(shù)據(jù)庫的方法 c語言連接mysql
- linux使用gcc編譯c語言共享庫步驟
- linux根據(jù)pid獲取進程名和獲取進程pid(c語言獲取pid)
- linux c語言操作數(shù)據(jù)庫(連接sqlite數(shù)據(jù)庫)
- linux下C語言中的mkdir函數(shù)與rmdir函數(shù)
- 淺析如何在c語言中調(diào)用Linux腳本
- 深入分析Linux下如何對C語言進行編程
- Linux系統(tǒng)中C語言編程創(chuàng)建函數(shù)fork()執(zhí)行解析
- C語言編寫獲取Linux本地目錄及本機信息的小程序?qū)嵗?/a>
相關(guān)文章
php進程(線程)通信基礎(chǔ)之System V共享內(nèi)存簡單實例分析
這篇文章主要介紹了php進程(線程)通信基礎(chǔ)之System V共享內(nèi)存,結(jié)合簡單實例形式分析了PHP System V共享內(nèi)存原理、相關(guān)函數(shù)與基本使用技巧,需要的朋友可以參考下2019-11-11php判斷str字符串是否是xml格式數(shù)據(jù)的方法示例
這篇文章主要介紹了php判斷str字符串是否是xml格式數(shù)據(jù)的方法,結(jié)合實例形式較為詳細的分析了php采用自定義函數(shù)針對xml格式數(shù)據(jù)進行驗證的相關(guān)操作技巧,需要的朋友可以參考下2017-07-07