Login
网站首页 > 文章中心 > 其它

c语言实现php框架_php不用框架怎么实现

作者:小编 更新时间:2023-10-11 12:43:23 浏览量:402人看过

如何看待C语言开发PHP框架

C语言开发的主流框架有哪些

c语言写的php框架 , ,yaf框架. phalcon框架.

c语言写的php框架 ,yaf框架. phalcon框架.

如何用C语言编写PHP扩展的详解

①.:预定义

在home目录,也可以其他任意目录,写一个文件,例如caleng_module.def

内容是你希望定义的函数名以及参数:

int a(int x,int y)

string b(string str,int n)

执行命令,生成对应扩展目录

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

去掉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])

代码如下:

/* {{{ proto int a(int x, int y)

?*/

PHP_FUNCTION(a)

{

int argc = ZEND_NUM_ARGS();

int x;

int y;

?int z;

if (zend_parse_parameters(argc TSRMLS_CC, "ll", x, y) == FAILURE)

return;

z=x◆y;

RETURN_LONG(z);

}

/* }}} */

/* {{{ proto string b(string str, int n)

PHP_FUNCTION(b)

char *str = NULL;

?int argc = ZEND_NUM_ARGS();

?int str_len;

?long n;

?char *result;

?char *ptr;

?int result_length;

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

? ? ?return;

?result_length = str_len * n;

?result = (char *) emalloc(result_length ◆ 1);

?ptr = result;

?while (n--) {

? ? ?memcpy(ptr, str, str_len);

? ? ?ptr ◆= str_len;

?}

?*ptr = '\0';

?RETURN_STRINGL(result, result_length, 0);

#cd ./caleng_module

#/usr/local/php/bin/phpize

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

#make

#make install

如上图所示

改目录下有生成的caleng_module.so文件

php.ini如果找不到可以从phpinfo()打出的信息看到

#cd /usr/local/php/lib/

php.ini增加扩展信息

extension=caleng_module.so

/usr/local/php/bin/php -m

①.0:PHP调用

下面是原文

Linux下用C开发PHP扩展

第二段:假设我们要开发一个名为caleng_module的扩展,该扩展包含两个函数:a--处理两个整型相加和b-处理字符串重复输出;

①.、首先编写一个函数定义文件,该文件编写函数原型后缀为def,假设为:caleng_module.def

int a(int x, int y)

string b(string str, int n)

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

PHP_ARG_ENABLE(myfunctions, whether to enable myfunctions support,

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

?int x, y, z;

?if (zend_parse_parameters(argc TSRMLS_CC, "ll", x, y) == FAILURE)

?z = x ◆ y;

?RETURN_LONG(z);

?char *str = NULL;

第三段:编译安装,假设php的安装目录为:/usr/localhost/webserver/php

# /usr/localhost/webserver/php/bin/phpize

# ./configure --with-php-config=/usr/localhost/webserver/php/bin/php-config

# make

# make install

在php.ini配置文件中加入: extension=caleng_module.so.

以上就是土嘎嘎小编为大家整理的c语言实现php框架相关主题介绍,如果您觉得小编更新的文章只要能对粉丝们有用,就是我们最大的鼓励和动力,不要忘记讲本站分享给您身边的朋友哦!!

版权声明:倡导尊重与保护知识产权。未经许可,任何人不得复制、转载、或以其他方式使用本站《原创》内容,违者将追究其法律责任。本站文章内容,部分图片来源于网络,如有侵权,请联系我们修改或者删除处理。

编辑推荐

热门文章