찾다
php教程php手册linux下 C语言对 php 扩展

linux下 C语言对 php 扩展

Jun 13, 2016 pm 12:25 PM
linuxphp하나아래에다운로드만들다설치하다오른쪽확장하다짓다소스 코드환경엮다압축을 푼다언어

一,搭建php环境
下载php 5.2.6 源码 并解压
编译安装,搭建php环境

二,创建扩展项目

进入源码目录
cd php5.2.6/ext/
./ext_skel --extname=my_ext
创建名字为my_ext的项目,最终会生成my_ext.so

三,更改配置和程序
$ vi ext/my_ext/config.m4

根据你自己的选择将

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: 如果出现: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
   say_hello();
?>

$ /usr/local/php/bin/php test.php
hello world.

则大功告成

ps:如有问题请留言,大家共同探讨

성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.

핫 AI 도구

Undresser.AI Undress

Undresser.AI Undress

사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover

AI Clothes Remover

사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool

Undress AI Tool

무료로 이미지를 벗다

Clothoff.io

Clothoff.io

AI 옷 제거제

AI Hentai Generator

AI Hentai Generator

AI Hentai를 무료로 생성하십시오.

인기 기사

R.E.P.O. 에너지 결정과 그들이하는 일 (노란색 크리스탈)
3 몇 주 전By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. 최고의 그래픽 설정
3 몇 주 전By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. 아무도들을 수없는 경우 오디오를 수정하는 방법
3 몇 주 전By尊渡假赌尊渡假赌尊渡假赌
WWE 2K25 : Myrise에서 모든 것을 잠금 해제하는 방법
4 몇 주 전By尊渡假赌尊渡假赌尊渡假赌

뜨거운 도구

SublimeText3 Linux 새 버전

SublimeText3 Linux 새 버전

SublimeText3 Linux 최신 버전

SublimeText3 Mac 버전

SublimeText3 Mac 버전

신 수준의 코드 편집 소프트웨어(SublimeText3)

ZendStudio 13.5.1 맥

ZendStudio 13.5.1 맥

강력한 PHP 통합 개발 환경

Eclipse용 SAP NetWeaver 서버 어댑터

Eclipse용 SAP NetWeaver 서버 어댑터

Eclipse를 SAP NetWeaver 애플리케이션 서버와 통합합니다.

에디트플러스 중국어 크랙 버전

에디트플러스 중국어 크랙 버전

작은 크기, 구문 강조, 코드 프롬프트 기능을 지원하지 않음