linux下 C語言對(duì) php 擴(kuò)展
更新時(shí)間:2008年12月14日 17:57:40 作者:
linux C語言對(duì) php 擴(kuò)展的設(shè)置技巧
一,搭建php環(huán)境
下載php 5.2.6 源碼 并解壓
編譯安裝,搭建php環(huán)境
二,創(chuàng)建擴(kuò)展項(xiàng)目
進(jìn)入源碼目錄
cd php5.2.6/ext/
./ext_skel --extname=my_ext
創(chuàng)建名字為my_ext的項(xiàng)目,最終會(huì)生成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.……的錯(cuò)誤信息,則需要安裝 autoconf (安裝過程略)
$ ./configure --with-php-config=/usr/local/php/bin/php-config
$ make
這時(shí)會(huì)編譯出 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
六,測(cè)試
$ vi test.php
<?php
say_hello();
?>
$ /usr/local/php/bin/php test.php
hello world.
則大功告成
ps:如有問題請(qǐng)留言,大家共同探討
下載php 5.2.6 源碼 并解壓
編譯安裝,搭建php環(huán)境
二,創(chuàng)建擴(kuò)展項(xiàng)目
進(jìn)入源碼目錄
cd php5.2.6/ext/
./ext_skel --extname=my_ext
創(chuàng)建名字為my_ext的項(xiàng)目,最終會(huì)生成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.……的錯(cuò)誤信息,則需要安裝 autoconf (安裝過程略)
$ ./configure --with-php-config=/usr/local/php/bin/php-config
$ make
這時(shí)會(huì)編譯出 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
六,測(cè)試
$ vi test.php
<?php
say_hello();
?>
$ /usr/local/php/bin/php test.php
hello world.
則大功告成
ps:如有問題請(qǐng)留言,大家共同探討
您可能感興趣的文章:
- C語言編寫Linux守護(hù)進(jìn)程實(shí)例
- linux安裝mysql和使用c語言操作數(shù)據(jù)庫(kù)的方法 c語言連接mysql
- linux使用gcc編譯c語言共享庫(kù)步驟
- linux根據(jù)pid獲取進(jìn)程名和獲取進(jìn)程pid(c語言獲取pid)
- linux c語言操作數(shù)據(jù)庫(kù)(連接sqlite數(shù)據(jù)庫(kù))
- linux下C語言中的mkdir函數(shù)與rmdir函數(shù)
- 淺析如何在c語言中調(diào)用Linux腳本
- 深入分析Linux下如何對(duì)C語言進(jìn)行編程
- Linux系統(tǒng)中C語言編程創(chuàng)建函數(shù)fork()執(zhí)行解析
- C語言編寫獲取Linux本地目錄及本機(jī)信息的小程序?qū)嵗?/a>
相關(guān)文章
php進(jìn)程(線程)通信基礎(chǔ)之System V共享內(nèi)存簡(jiǎn)單實(shí)例分析
這篇文章主要介紹了php進(jìn)程(線程)通信基礎(chǔ)之System V共享內(nèi)存,結(jié)合簡(jiǎn)單實(shí)例形式分析了PHP System V共享內(nèi)存原理、相關(guān)函數(shù)與基本使用技巧,需要的朋友可以參考下2019-11-11php判斷str字符串是否是xml格式數(shù)據(jù)的方法示例
這篇文章主要介紹了php判斷str字符串是否是xml格式數(shù)據(jù)的方法,結(jié)合實(shí)例形式較為詳細(xì)的分析了php采用自定義函數(shù)針對(duì)xml格式數(shù)據(jù)進(jìn)行驗(yàn)證的相關(guān)操作技巧,需要的朋友可以參考下2017-07-07php一維二維數(shù)組鍵排序方法實(shí)例總結(jié)
這篇文章主要介紹了php一維二維數(shù)組鍵排序方法,以實(shí)例形式總結(jié)了針對(duì)一維數(shù)組的冒泡排序與使用array_multisort()對(duì)二位數(shù)組按照指定鍵值排序等方法,具有不錯(cuò)的參考借鑒價(jià)值,需要的朋友可以參考下2014-11-11