找回密码
 新建账号

php configure --with-openssl-argon2 --with-password-argon2

[复制链接]
 楼主| 大郎 发表于 2026-7-13 04:33 | 显示全部楼层 |阅读模式
PHP 的 configure --help 和手册,有时候惜字如金,让人困惑甚至抓狂,只能通过大量测试才能靠经验得出有用的结论。
这两个编译参数在 configure --help 中描述如下。
  1. --with-openssl-argon2   OPENSSL: Enable argon2 password hashing
  2. --with-password-argon2  Include Argon2 support in password_*
复制代码
正常人肯定看不懂,不会知道这二者有什么关系。PHP 手册又有如下文字。
  1. To enable Argon2 password hashing, PHP must be built either with libargon2 support using the --with-password-argon2 configure option or, starting from PHP 8.4.0, with OpenSSL using --with-openssl and --with-openssl-argon2.
复制代码
好吧,看到这段文字,终于知道 --with-openssl-argon2 和 --with-password-argon2 是 Argon2 的两种实现,在 PHP 8.4+ 中二选一就行,在早期版本中只能使用 --with-password-argon2。

然而天坑随之就来了,有很多扩展依赖于 openssl,而且 PHP 有 php php-cgi phpdbg 等诸多程序,将扩展编译成动态链接库可以节省不少磁盘空间,而静态编译将扩展嵌入主程序会让每一个程序都带一份扩展的副本,导致 PHP 整体变得臃肿。而且 --with-openssl-argon2 要求静态编译 openssl,也就是说 --with-openssl 不能写成 --with-openssl=shared,否则 --with-openssl-argon2 根本不会生效,而 --with-openssl-argon2 自己可以写成 --with-openssl-argon2=shared,但并不会编译出一个相关的 .so 动态扩展文件出来,只会为 password_* 系列函数提供 argon2i 和 argon2id 算法支持。
  1. php -r "print_r(password_algos());"
  2. Array
  3. (
  4.     [0] => 2y
  5.     [1] => argon2i
  6.     [2] => argon2id
  7. )
复制代码
  1. php -r "print_r(new ReflectionFunction('password_algos')->getExtension());"
  2. ReflectionExtension Object
  3. (
  4.     [name] => standard
  5. )
复制代码
所以,结论是,使用 --with-openssl-argon2 看起来可以不再依赖于 --with-password-argon2 背后的 libargon2,直接拿很多其他扩展都要使用的 openssl 来打底,而实际上它反而增加了麻烦,可能出现预料以外的结果,还不如就用 libargon2。等将来优化好了,大概还是能用 openssl 做底子,这应该是趋势。

手机版|轻松e站

GMT+8, 2026-7-26 18:49

快速回复 返回顶部 返回列表