linux下 C語言對 php 擴(kuò)展
更新時間:2008年12月14日 17:57:40 作者:
linux C語言對 php 擴(kuò)展的設(shè)置技巧
一,搭建php環(huán)境
下載php 5.2.6 源碼 并解壓
編譯安裝,搭建php環(huán)境
二,創(chuàng)建擴(kuò)展項目
進(jìn)入源碼目錄
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)建擴(kuò)展項目
進(jìn)入源碼目錄
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守護(hù)進(jìn)程實例
- linux安裝mysql和使用c語言操作數(shù)據(jù)庫的方法 c語言連接mysql
- linux使用gcc編譯c語言共享庫步驟
- linux根據(jù)pid獲取進(jìn)程名和獲取進(jìn)程pid(c語言獲取pid)
- linux c語言操作數(shù)據(jù)庫(連接sqlite數(shù)據(jù)庫)
- linux下C語言中的mkdir函數(shù)與rmdir函數(shù)
- 淺析如何在c語言中調(diào)用Linux腳本
- 深入分析Linux下如何對C語言進(jìn)行編程
- Linux系統(tǒng)中C語言編程創(chuàng)建函數(shù)fork()執(zhí)行解析
- C語言編寫獲取Linux本地目錄及本機(jī)信息的小程序?qū)嵗?/a>
相關(guān)文章
使用VisualStudio開發(fā)php的圖文設(shè)置方法
早先在asp橫行的年代,php和asp一樣,大都都是html中夾雜代碼,說實話,這時候IDE的確用處不是很大,倒是類似于dw之類的設(shè)計器甚為上手。2010-08-08
PHP簡單實現(xiàn)二維數(shù)組的矩陣轉(zhuǎn)置操作示例
這篇文章主要介紹了PHP簡單實現(xiàn)二維數(shù)組的矩陣轉(zhuǎn)置操作,涉及php針對二維數(shù)組的遍歷與運(yùn)算操作技巧,需要的朋友可以參考下2017-11-11
深入探討:PHP使用數(shù)據(jù)庫永久連接方式操作MySQL的是與非
本篇文章是對PHP使用數(shù)據(jù)庫永久連接方式操作MySQL的是與非進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-06-06
自己寫的兼容低于PHP 5.5版本的array_column()函數(shù)
這篇文章主要介紹了自己寫的兼容低于PHP 5.5版本的array_column()函數(shù),array_column是PHP 5.5新增函數(shù),有時在低版本中也可能要用到,需要的朋友可以參考下2014-10-10
CKEditor4結(jié)合php實現(xiàn)上傳圖片功能
ckedit4是沒有圖片上傳功能的,單我們可以通過配置?config.js?文件來設(shè)置圖片上傳的接口,然后結(jié)合后端程序?qū)崿F(xiàn)圖片上傳,本文講解CKEditor4結(jié)合php實現(xiàn)上傳圖片功能的方法2024-03-03
利用PHPExcel實現(xiàn)Excel文件的寫入和讀取
本篇文章主要介紹了利用PHPExcel實現(xiàn)Excel文件的寫入和讀取的相關(guān)知識。具有很好的參考價值。下面跟著小編一起來看下吧2017-04-04

