我在 Windows 计算机上使用 PHP 8.2 启动 Redis 5.3.7 时遇到困难。当我尝试启动它时,会显示一个对话框,其中包含以下消息:
“无法在动态链接库c:\Program Files\php xt\php_redis.dll中定位程序入口点_zend_get_parameters_array_ex”
我已包含以下错误的屏幕截图:
这是我解决问题的方法
转到此页面https://github.com/phpredis/phpredis/actions/runs/5916330188#artifacts,那里列出了扩展。
在 Windows 11 上的 xampp、php8.2.1 和 redis 3.2.100 上为我工作
如何在 Windows 下编译像 Redis 这样的 PHP 扩展。因为没有人真正解释这一点。
在旧的 Windows shell 下运行命令,例如
cmd.exe
您将需要 2019 版的 Microsoft C/C++ 编译器,因此链接器与可下载的 Windows 版 PHP 兼容。
winget
可以在 Windows 应用商店中找到“App Installer”。
winget install --id Microsoft.VisualStudio.2022.BuildTools
在 Visual Studio Build Tools 2022 的“单独组件”选项卡下“修改”安装,然后选择:
下载 Windows 版 PHP,同时下载并解压“开发包(用于开发 PHP 扩展的 SDK)”,也可能下载“调试包”。在“开发包”中有一个文件夹,您需要将该文件夹的内容解压到您所在的文件夹
php.exe
。 https://windows.php.net/download#php-8.2
Git克隆https://github.com/phpredis/phpredis在你有
php.exe
的文件夹中。
winget install --id Git.Git
git clone https://github.com/phpredis/phpredis.git
# or:
winget install --id Git.Git
winget install --id GitHub.cli
gh repo clone phpredis/phpredis
您可能想从主
develop
分支切换:
git tag # find the latest non-RC version, currently that is 5.3.7
git checkout 5.3.7
在命令 shell
cmd.exe
所在目录内 php.exe
。
"C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Auxiliary\Build\vcvars64.bat" -vcvars_ver=14.29
.\configure.bat --enable-redis --with-prefix=%cd%\..
检查Makefile中的
PHP_PREFIX
和PHP_SRC_DIR
指向包含php.exe和phpredis源代码的目录,例如
PHP_SRC_DIR ="C:\laragon\bin\php\php-8.2.7-Win32-vs16-x64\phpredis"
PHP_PREFIX="C:\laragon\bin\php\php-8.2.7-Win32-vs16-x64\"
然后构建:
nmake clean
nmake
copy x64\Release_TS\php_redis.dll ..\ext\
在 php.ini 中:
extension=php_redis.dll
然后运行
php -m
查看列出的 redis。