前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >手把手撸PHP扩展 0x02: 整理文件

手把手撸PHP扩展 0x02: 整理文件

作者头像
桶哥
发布2019-07-10 18:07:48
3620
发布2019-07-10 18:07:48
举报
文章被收录于专栏:PHP饭米粒PHP饭米粒PHP饭米粒

在开发之前,我们先对项目的文件以及文件的内容进行整理,让结构更加的清晰。整理的依据是开发规范。

首先,我们修改php_study.h文件的内容如下:

#ifndef PHP_STUDY_H
#define PHP_STUDY_H

#include "php.h"
#include "php_ini.h"
#include "ext/standard/info.h"

#include "study.h"

#define PHP_STUDY_VERSION "0.1.0"

extern zend_module_entry study_module_entry;
#define phpext_study_ptr &study_module_entry

#ifdef PHP_WIN32
#	define PHP_STUDY_API __declspec(dllexport)
#elif defined(__GNUC__) && __GNUC__ >= 4
#	define PHP_STUDY_API __attribute__ ((visibility("default")))
#else
#	define PHP_STUDY_API
#endif

#ifdef ZTS
#include "TSRM.h"
#endif

/**
 * Declare any global variables you may need between the BEGIN and END macros here
 */
ZEND_BEGIN_MODULE_GLOBALS(study)

ZEND_END_MODULE_GLOBALS(study)

#endif	/* PHP_STUDY_H */

然后,在include目录里面创建文件study.h,内容如下:

#ifndef STUDY_H_
#define STUDY_H_

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

// include standard library
#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <inttypes.h>
#include <limits.h>
#include <math.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <signal.h>
#include <time.h>

#include <fcntl.h>
#include <unistd.h>
#include <pthread.h>
#include <poll.h>

#include <arpa/inet.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <netdb.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <sys/select.h>
#include <sys/mman.h>
#include <sys/ipc.h>
#include <sys/wait.h>
#include <sys/un.h>
#include <sys/types.h>
#include <sys/utsname.h>
#include <sys/stat.h>

#endif /* STUDY_H_ */

然后,我们再把study.c文件命名为study.cc,修改里面的内容为:

#include "php_study.h"

PHP_MINIT_FUNCTION(study)
{
	return SUCCESS;
}

PHP_MSHUTDOWN_FUNCTION(study)
{
	return SUCCESS;
}

PHP_RINIT_FUNCTION(study)
{
	return SUCCESS;
}

PHP_RSHUTDOWN_FUNCTION(study)
{
	return SUCCESS;
}

PHP_MINFO_FUNCTION(study)
{
	php_info_print_table_start();
	php_info_print_table_header(2, "study support", "enabled");
	php_info_print_table_end();
}

const zend_function_entry study_functions[] = {
	PHP_FE_END
};

zend_module_entry study_module_entry = {
	STANDARD_MODULE_HEADER,
	"study",
	study_functions,
	PHP_MINIT(study),
	PHP_MSHUTDOWN(study),
	PHP_RINIT(study),
	PHP_RSHUTDOWN(study),
	PHP_MINFO(study),
	PHP_STUDY_VERSION,
	STANDARD_MODULE_PROPERTIES
};

#ifdef COMPILE_DL_STUDY
ZEND_GET_MODULE(study)
#endif

因为,我们修改了study.cc的文件名字,所以我们需要修改config.m4里面的文件:

study_source_file="\
  study.cc \
  ${STUDY_ASM_DIR}make_${STUDY_CONTEXT_ASM_FILE} \
  ${STUDY_ASM_DIR}jump_${STUDY_CONTEXT_ASM_FILE}
"

study.c改成了study.cc

OK,整理完毕。

下一篇:理解PHP生命周期的过程

本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2019-07-05,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 PHP饭米粒 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档