You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

通过Composer引入wkhtmltopdf二进制文件时遇QSslSocket错误求助

解决Laravel-Snappy使用Composer依赖的wkhtmltopdf时的SSL函数解析错误

问题描述

尝试不本地安装wkhtmltopdf,而是通过Laravel-Snappy文档中「wkhtmltopdf binary as composer dependencies」章节的方式引入,但运行时出现大量QSslSocket相关的函数解析错误,最终导致页面加载失败,错误信息如下:

QSslSocket: cannot resolve CRYPTO_num_locks                  ] 10%
QSslSocket: cannot resolve CRYPTO_set_id_callback
QSslSocket: cannot resolve CRYPTO_set_locking_callback
QSslSocket: cannot resolve sk_free
QSslSocket: cannot resolve sk_num
QSslSocket: cannot resolve sk_pop_free
QSslSocket: cannot resolve sk_value
QSslSocket: cannot resolve SSL_get_peer_certificate
QSslSocket: cannot resolve SSL_library_init
QSslSocket: cannot resolve SSL_load_error_strings
QSslSocket: cannot resolve SSLv3_client_method
QSslSocket: cannot resolve SSLv23_client_method
QSslSocket: cannot resolve SSLv3_server_method
QSslSocket: cannot resolve SSLv23_server_method
QSslSocket: cannot resolve X509_STORE_CTX_get_chain
QSslSocket: cannot resolve OPENSSL_add_all_algorithms_noconf
QSslSocket: cannot resolve OPENSSL_add_all_algorithms_conf
QSslSocket: cannot resolve SSLeay
QSslSocket: cannot call unresolved function CRYPTO_num_locks
QSslSocket: cannot call unresolved function CRYPTO_set_id_callback
QSslSocket: cannot call unresolved function CRYPTO_set_locking_callback
QSslSocket: cannot call unresolved function SSL_library_init
QSslSocket: cannot call unresolved function SSLv23_client_method
QSslSocket: cannot call unresolved function sk_num
QSslSocket: cannot call unresolved function SSLv23_client_method
QSslSocket: cannot call unresolved function SSL_library_init
Error: Failed loading page  (sometimes it will work just to ignore this error with --load-error-handling ignore)
Exit with code 1 due to network error: UnknownNetworkError
QSslSocket: cannot call unresolved function CRYPTO_num_locks
QSslSocket: cannot call unresolved function CRYPTO_set_id_callback
QSslSocket: cannot call unresolved function CRYPTO_set_locking_callback

已尝试安装openssl库、公共库,但因为使用的是Composer引入的二进制文件,这些操作没解决问题,求可行方案。

解决方案

1. 确保系统安装兼容的OpenSSL库并更新缓存

Composer引入的wkhtmltopdf二进制包仍依赖系统底层的OpenSSL库,需确保版本兼容并正确链接:

  • Debian/Ubuntu系统:
    sudo apt-get update && sudo apt-get install -y openssl libssl-dev
    
  • CentOS/RHEL系统:
    sudo yum install -y openssl openssl-devel
    

安装完成后更新系统库缓存:

sudo ldconfig

2. 在Snappy配置中指定SSL库路径

如果系统SSL库路径未被自动识别,可在Laravel的config/snappy.php配置文件中手动指定:

return [
    'pdf' => [
        'enabled' => true,
        'binary' => env('WKHTMLTOPDF_BINARY', base_path('vendor/h4cc/wkhtmltopdf-amd64/bin/wkhtmltopdf-amd64')),
        'timeout' => 360,
        'options' => [
            'load-error-handling' => 'ignore',
            'ssl-ca-path' => '/etc/ssl/certs',
        ],
        'env' => [
            'LD_LIBRARY_PATH' => '/usr/lib/x86_64-linux-gnu/', // 根据系统架构调整路径
        ],
    ],
];

3. 替换为官方预编译的wkhtmltopdf二进制包

Composer的h4cc/wkhtmltopdf-*包可能存在兼容性问题,可更换为官方预编译包:

  1. 移除当前Composer依赖:
    composer remove h4cc/wkhtmltopdf-amd64 h4cc/wkhtmltoimage-amd64
    
  2. 下载对应系统架构的官方预编译包,解压后放到项目目录(如storage/bin/),并在配置文件中指定路径:
    'binary' => env('WKHTMLTOPDF_BINARY', storage_path('bin/wkhtmltopdf')),
    
  3. 给二进制文件添加执行权限:
    chmod +x storage/bin/wkhtmltopdf
    

4. 启用加载错误忽略参数

根据错误提示,可在Snappy配置中添加load-error-handling选项跳过部分SSL加载错误:

'options' => [
    'load-error-handling' => 'ignore',
],

内容的提问来源于stack exchange,提问作者Ruan Vinicius

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.24 01:27:06