惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

V
Visual Studio Blog
J
Java Code Geeks
H
Hackread – Cybersecurity News, Data Breaches, AI and More
D
Docker
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
博客园 - 聂微东
MyScale Blog
MyScale Blog
H
Help Net Security
Last Week in AI
Last Week in AI
T
The Blog of Author Tim Ferriss
M
MIT News - Artificial intelligence
大猫的无限游戏
大猫的无限游戏
酷 壳 – CoolShell
酷 壳 – CoolShell
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
P
Proofpoint News Feed
博客园 - 叶小钗
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Y
Y Combinator Blog
Recent Announcements
Recent Announcements
F
Fortinet All Blogs
Martin Fowler
Martin Fowler
Microsoft Security Blog
Microsoft Security Blog
T
Tailwind CSS Blog
aimingoo的专栏
aimingoo的专栏

zodream梦想开源/个人编程日记

文件解析笔记-zodream梦想开源/个人编程日记 密码本开发笔记之读写与保存-zodream梦想开源/个人编程日记 SkiaSharp 把 pixel byte[] 转成 SKBitmap-zodream梦想开源/个人编程日记 nas 使用 Docker 安装 gogs-zodream梦想开源/个人编程日记 复制 android 手机中的文件到电脑-zodream梦想开源/个人编程日记 周报:寻找优质的周刊-zodream梦想开源/个人编程日记 开发日志:对Markdown的代码块新增引用来源支持-zodream梦想开源/个人编程日记 周报:怎么写技术类的教程文章-zodream梦想开源/个人编程日记 css display:flex 布局尺寸超出问题-zodream梦想开源/个人编程日记 周报:SEO优化的思考-zodream梦想开源/个人编程日记 Edge 浏览器不适用 Edge Image Viewer 打开图片 -zodream梦想开源/个人编程日记 SEO 学习笔记(一) 内容来源-zodream梦想开源/个人编程日记 PHP 实现双因素身份认证(2FA)-zodream梦想开源/个人编程日记 WPF MVVM 获取List 多选数据-zodream梦想开源/个人编程日记 Burp Suite 抓包-zodream梦想开源/个人编程日记 使用 indexnow 注意事项-zodream梦想开源/个人编程日记 Godot 使用字体图标 例如: Iconfont、FontAwesome-zodream梦想开源/个人编程日记 angular 15 对指定页面进行访问限制-zodream梦想开源/个人编程日记 CSS 使用 column-count 实现瀑布流出现内容分割的解决办法-zodream梦想开源/个人编程日记 input 确认按键事件在手机端不生效-zodream梦想开源/个人编程日记 C# 使用socket 进行通讯-zodream梦想开源/个人编程日记 Maui开发中Windows应用开启管理员权限-zodream梦想开源/个人编程日记 Maui 中自定义控件-zodream梦想开源/个人编程日记 angular 14 使用 ng-template 实现tree 结构显示-zodream梦想开源/个人编程日记 c# 动态安装和卸载dll-zodream梦想开源/个人编程日记 慎用 CompositionTarget.Rendering-zodream梦想开源/个人编程日记 c# 重写 c++ 程序笔记:数据初始化-zodream梦想开源/个人编程日记 源码编译 aseprite-zodream梦想开源/个人编程日记 记录一下字符串分隔split各语言之间的不同-zodream梦想开源/个人编程日记 c# Gzip解码无头内容-zodream梦想开源/个人编程日记
VS2019 开发PHP 拓展(二)创建空拓展-zodream梦想开源/个人...
zodream · 2020-03-22 · via zodream梦想开源/个人编程日记

VS2019 开发PHP 拓展(二)创建空拓展

生成空的拓展

命令行进入 D:\zodream\php-sdk-binary-tools\phpdev\vs16\x64\php-src\ext

这里zodream代表你的php扩展名

php ext_skel.php --ext zodream

1

vs2019 载入项目

  1. 打开 Visual Studio 2019
  2. 选择 继续但无需代码
  3. 打开菜单 文件 -> 新建 -> 从现有代码创建项目
  4. 选择 Visual C++ 下一步
  5. 项目文件位置(拓展的目录D:\zodream\php-sdk-binary-tools\phpdev\vs16\x64\php-src\ext\zodream),项目名称 phpzodream,下一步
  6. 项目类型选择 动态链接库(DLL)项目,完成
  7. 菜单栏选配置 Release x64
  8. 右键项目属性 -> C/C++ -> 常规 -> 附加包含目录 -> 编辑,加入目录
D:\zodream\php-sdk-binary-tools\phpdev\vs16\x64\php-src
D:\zodream\php-sdk-binary-tools\phpdev\vs16\x64\php-src\main
D:\zodream\php-sdk-binary-tools\phpdev\vs16\x64\php-src\TSRM
D:\zodream\php-sdk-binary-tools\phpdev\vs16\x64\php-src\Zend

1234

属性 -> C/C++ -> 预处理器 -> 预处理器定义 -> 编辑 加入以下变量(其中ZODREAM替换成php扩展名

ZEND_DEBUG=0
PHP_EXTENSION
PHP_WIN32
ZEND_WIN32
HAVE_ZODREAM=1
COMPILE_DL_ZODREAM

123456

如果为开启线程安全 则加上

  1. 生成

可能报错

  1. 如果提示LINK 1561: 必须定义入口点

属性 -> 常规 -> 配置类型 选择 动态库(.dll)

  1. E0020: 未定义标识符arginfo_test1 或者 缺少 zodream_arginfo.h C1083 无法打开包括文件: “zodream_arginfo.h”: No such file or directory

请复制 D:\zodream\php-sdk-binary-tools\phpdev\vs16\x64\php-src\ext\skeleton\skeleton_arginfo.hzodream_arginfo.h 即可

或者在 ext_skel.php 文件中的 copy_sources 方法 加上 'skeleton_arginfo.h' => $options['ext'] . '_arginfo.h'

function copy_sources() {
    global $options;

    $files = [
            'skeleton.c'         => $options['ext'] . '.c',
            'skeleton.stub.php'  => $options['ext'] . '.stub.php',
            'php_skeleton.h'     => 'php_' . $options['ext'] . '.h',
            'skeleton_arginfo.h' => $options['ext'] . '_arginfo.h'  // 加上这行就会自动生成
            ];

}

123456789101112

  1. LNK2019 无法解析的外部符号 __imp_zend_strpprintf

属性 -> 连接器 -> 输入 -> 附加依赖项 -> 编辑 加入一个php.lib,此文件在正式发布的PHP程序中 例如 D:\zodream\php\php-7.4-nts\dev\php7.lib

  1. E0020 未定义标识符 "zif_test2"

因为定义的方式 PHP_FUNCTION(zodream_test2) 但是引入时用的是 PHP_FE(test2, arginfo_test2)

改为

PHP_FUNCTION(test2)
{

1234

或者改 D:\zodream\php-sdk-binary-tools\phpdev\vs16\x64\php-src\ext\skeleton\skeleton.c

/* {{{ string test2( [ string $var ] )
 */
PHP_FUNCTION(test2)
{
    char *var = "World";
    size_t var_len = sizeof("World") - 1;
    zend_string *retval;

    ZEND_PARSE_PARAMETERS_START(0, 1)
        Z_PARAM_OPTIONAL
        Z_PARAM_STRING(var, var_len)
    ZEND_PARSE_PARAMETERS_END();

    retval = strpprintf(0, "Hello %s", var);

    RETURN_STR(retval);
}

123456789101112131415161718

使用

这是在正式时使用

把生成的 phpzodream.dll 复制到正式环境 ext 文件夹下,

修改 php.ini 引入插件

重启 iis

当前为测试时

按【上一章】编译 php 即可,不需要在ini配置,直接使用即可

在php 代码加入

test1();

echo test2();

1234

查看效果

转载请保留原文链接: https://zodream.cn/blog/id/102.html