1. In Yii2, when calling file_get_contents(“https://api.weixin.qq.com”);, an error occurs: yii\base\ErrorException: file_get_contents(): SSL operation failed with code 1. OpenSSL Error messages:. As shown in Figure 1

Plaintext
2025-03-11 17:56:30 [101.204.100.38][1826027541133144][-][error][yii\base\ErrorException:2] yii\base\ErrorException: file_get_contents(): SSL operation failed with code 1. OpenSSL Error messages:
error:0A000126:SSL routines::unexpected eof while reading in /home/wwwroot/object/src/api/controllers/UserController.php:189
Stack trace:
#0 [internal function]: yii\base\ErrorHandler->handleError()
#1 /home/wwwroot/object/src/api/controllers/UserController.php(189): file_get_contents()
2. PHP requires a valid CA certificate to verify the remote server’s SSL certificate. If the CA certificate is missing or expired, SSL verification will fail.
Plaintext
[root@iZ2zeaj7tnbv8d3gsoy1w5Z ~]# cp -f cacert.pem /etc/ssl/certs/cacert.pem
[root@iZ2zeaj7tnbv8d3gsoy1w5Z ~]# cd /etc/ssl/certs/
[root@iZ2zeaj7tnbv8d3gsoy1w5Z certs]# ls -l
total 228
lrwxrwxrwx 1 root root 49 Aug 19 2024 ca-bundle.crt -> /etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem
lrwxrwxrwx 1 root root 55 Aug 19 2024 ca-bundle.trust.crt -> /etc/pki/ca-trust/extracted/openssl/ca-bundle.trust.crt
-rw-r--r-- 1 root root 233263 Mar 11 17:53 cacert.pem
[root@iZ2zeaj7tnbv8d3gsoy1w5Z certs]#
3. Configure openssl.cafile in php.ini. After restarting php-fpm, it still does not work. As shown in Figure 2

Plaintext
openssl.cafile = /etc/ssl/certs/cacert.pem
4. Finally, I had to reimplement the request using curl, which successfully resolved the issue. Reference: Troubleshooting analysis for curl requests to https URLs returning false
