熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> PHP編程 >> 正文

Linux下C語言對PHP擴展

2013-11-15 12:22:07  來源: PHP編程 

  一搭建php環境

  下載php 源碼 並解壓

  編譯安裝搭建php環境

  二創建擴展項目

  進入源碼目錄

  cd php/ext/

  /ext_skel extname=my_ext

  創建名字為my_ext的項目最終會生成my_extso

  三更改配置和程序

  $ vi ext/my_ext/configm

  根據你自己的選擇將

  dnl PHP_ARG_WITH(my_ext for my_ext support

  dnl Make sure that the comment is aligned:

  dnl [ withmy_ext Include my_ext support])

  修改成

  PHP_ARG_WITH(my_ext for my_ext support

  Make sure that the comment is aligned:

  [ withmy_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 [ enablemy_ext Enable my_ext support])

  修改成

  PHP_ARG_ENABLE(my_ext whether to enable my_ext support

  Make sure that the comment is aligned:

  [ enablemy_ext Enable my_ext support])

  $ vi ext/my_ext/php_my_exth

  將

  PHP_FUNCTION(confirm_my_ext_compiled); /* For testing remove later */

  更改為

  PHP_FUNCTION(say_hello);

  $ vi ext/my_ext/my_extc

  將

  zend_function_entry phpcpp_functions[] = {

  PHP_FE(confirm_my_ext_compiled NULL) /* For testing remove later */

  {NULL NULL NULL} /* Must be the last line in phpcpp_functions[] */

  };

  更改為

  zend_function_entry phpcpp_functions[] = {

  PHP_FE(say_hello NULL)

  {NULL NULL NULL} /* Must be the last line in phpcpp_functions[] */

  };

  在最後添加

  PHP_FUNCTION(say_hello)

  {

  zend_printf(hello world\n);

  }

  四編譯

  $ cd my_ext

  $ /usr/local/php/bin/phpize

  ps: 如果出現Cannot find autoconf……的錯誤信息則需要安裝 autoconf (安裝過程略)

  $ /configure withphpconfig=/usr/local/php/bin/phpconfig

  $ make

  這時會編譯出 my_ext/modules/my_extso

  五配置phpini

  將my_extso放入/usr/local/php/ext/目錄

  $ vi phpini

  修改添加如下

  extension_dir = /usr/local/php/ext/

  extension=my_extso

  六測試

  $ vi testphp

  <?php

  say_hello();

  ?>

  $ /usr/local/php/bin/php testphp

  hello world

  則大功告成


From:http://tw.wingwit.com/Article/program/PHP/201311/20822.html
    推薦文章
    Copyright © 2005-2013 電腦知識網 Computer Knowledge   All rights reserved.