日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > php >内容正文

php

c写成php的扩展_用C语言编写PHP扩展

發布時間:2024/7/5 php 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 c写成php的扩展_用C语言编写PHP扩展 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1:預定義

vi myfunctions.def

string self_concat(string str, int n)

2:到PHP源碼目錄的ext目錄

#cd /usr/local/php-5.4.0/ext/

執行命令,生成對應擴展目錄

#./ext_skel --extname=caleng_module --proto=/home/hm/caleng_module.def

./ext_skel --extname=myfunctions --proto=myfunctions.def

3:修改config.m4

vi config.m4

去掉dnl的注釋

PHP_ARG_ENABLE(caleng_module, whether to enable caleng_module support,

Make sure that the comment is aligned:

[? --enable-caleng_module? ? ? ? ? Enable caleng_module support])

php源碼根目錄

./buildconf

修改vi myfunctions.c

PHP_FUNCTION(self_concat)

{

char *str = NULL;

int argc = ZEND_NUM_ARGS();

int str_len;

long n;

char *result; /* Points to resulting string */

char *ptr; /* Points at the next location we want to copy to */

int result_length; /* Length of resulting string */

if (zend_parse_parameters(argc TSRMLS_CC, "sl", &str, &str_len, &n) == FAILURE)

return;

/* Calculate length of result */

result_length = (str_len * n);

/* Allocate memory for result */

result = (char *) emalloc(result_length + 1);

/* Point at the beginning of the result */

ptr = result;

while (n--) {

/* Copy str to the result */

memcpy(ptr, str, str_len);

/* Increment ptr to point at the next position we want to write to */

ptr += str_len;

}

/* Null terminate the result. Always null-terminate your strings

even if they are binary strings */

*ptr = '\0';

/* Return result to the scripting engine without duplicating it*/

RETURN_STRINGL(result, result_length, 0);

}

執行

/usr/local/php/bin/phpize

./configure --with-php-config=/usr/local/php/bin/php-config

make

make install

修改

vi php.ini

php.ini增加擴展信息

extension=myfunctions.so

重啟Nginx和php-fpm。

檢查有沒有加載都這個模塊了

/usr/local/php/bin/php -m 或者 phpinfo()

把PHP加入到環境變量? export PATH=$PATH:/usr/local/webserver/php/bin

執行

php -r "echo self_concat('One', 3);"

參考:

http://www.cnblogs.com/benio/archive/2010/09/25/1834655.html

http://www.laruence.com/2008/08/16/301.html

http://blog.csdn.net/sanbingyutuoniao123/article/details/51921510

總結

以上是生活随笔為你收集整理的c写成php的扩展_用C语言编写PHP扩展的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。