專案使用了第三方包 tecnickcom/TCPDF
生成 PDF 檔案,需要插入圖片到檔案中。
然後發生了以下報錯:
[ error ] [2]getimagesize(): SSL operation failed with code 1. OpenSSL Error messages:
error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed
[ error ] [2]getimagesize(): Failed to enable crypto
[ error ] [2]getimagesize(https://www.xxx.com/static/upload/default-avatar.jpg): failed to open stream: operation failed
[ error ] [2]file_get_contents(): SSL operation failed with code 1. OpenSSL Error messages:
error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed
解決方案:
PHP 在發起 HTTPS 請求的時候,需要本地證照自驗,也可以跳過不驗證,我這裡使用了驗證證照。
先下載一個 CA
證照
wget http://curl.haxx.se/ca/cacert.pem
配置一下 php.ini
[openssl]
; The location of a Certificate Authority (CA) file on the local filesystem
; to use when verifying the identity of SSL/TLS peers. Most users should
; not specify a value for this directive as PHP will attempt to use the
; OS-managed cert stores in its absence. If specified, this value may still
; be overridden on a per-stream basis via the "cafile" SSL stream context
; option.
openssl.cafile= SSL證照絕對路徑
問題解決。
一般情況是不需要理會這個證照的,就是不明白為什麼 cafile 證照突然就失效了,但是
curl
是能發出https
請求的,所以感到很詭異,換了 cafile 證照之後就正常了。
本作品採用《CC 協議》,轉載必須註明作者和本文連結