curl 显示为已安装并启用,但在 php 中执行时抛出未定义的函数错误

问题描述 投票:0回答:1

运行在Centos 7系统上。 phpinfo() 说curl 已启用,但是当我运行此代码时:

<?php
// API
$url = 'https://api.openai.com/v1/embeddings';

// Create a new cURL resource
$ch = curl_init($url);
?>

我收到错误:PHP 致命错误:

未捕获错误:调用未定义的函数curl_init()

如果我尝试安装它,则表示它已安装:

yum install php-curl 
Package php-common-8.1.14-1.el7.remi.x86_64 already installed and latest version

一切都没有答案。 我可以从这里尝试什么? 为什么curl没有执行?

php --version
PHP 8.1.14 (cli) (built: Jan  4 2023 06:45:14) (NTS gcc x86_64)
Copyright (c) The PHP Group
Zend Engine v4.1.14, Copyright (c) Zend Technologies
    with Zend OPcache v8.1.14, Copyright (c), by Zend Technologies

phpinfo();
cURL support    enabled 
cURL Information    7.29.0 

php -i | grep "curl"
/etc/php.d/20-curl.ini,
curl
curl.cainfo => no value => no value

在/etc/php.d/20-curl.ini中:

扩展名=curl.so

yum list *curl*

Installed Packages
curl.x86_64                                        7.29.0-59.el7_9.1                       installed 
libcurl.x86_64                                     7.29.0-59.el7_9.1                       installed 
libcurl-devel.x86_64                               7.29.0-59.el7_9.1                       installed 
python-pycurl.x86_64                               7.19.0-19.el7                           @base     
Available Packages
collectd-curl.x86_64                               5.8.1-1.el7                             epel      
collectd-curl_json.x86_64                          5.8.1-1.el7                             epel      
collectd-curl_xml.x86_64                           5.8.1-1.el7                             epel      
curlftpfs.x86_64                                   0.9.2-14.el7                            epel      
flickcurl.x86_64                                   1.25-2.el7.nux                          nux-dextopflickcurl-debuginfo.x86_64                         1.25-2.el7.nux                          nux-dextopflickcurl-devel.x86_64                             1.25-2.el7.nux                          nux-dextopfuse-curlftpfs.x86_64                              0.9.1-1.el6.rf                          rpmforge  
libcurl.i686                                       7.29.0-59.el7_9.1                       updates   
libcurl-devel.i686                                 7.29.0-59.el7_9.1                       updates   
nbdkit-plugin-curl.x86_64                          1.2.7-2.el7                             epel      
ocaml-curl.x86_64                                  0.7.5-3.el7                             epel      
ocaml-curl-devel.x86_64                            0.7.5-3.el7                             epel      
perl-WWW-Curl.x86_64                               4.15-13.el7                             base      
php-pear-Net-Curl.noarch                           1.2.5-10.el7                            epel      
python34-pycurl.x86_64                             7.43.0-7.el7                            epel      
python36-pycurl.x86_64                             7.43.0-7.el7                            epel      
uwsgi-alarm-curl.x86_64                            2.0.18-8.el7                            epel      
uwsgi-plugin-curl-cron.x86_64                      2.0.18-8.el7                            epel      
php centos7 php-curl
1个回答
0
投票

文件损坏原来是罪魁祸首。

无论如何,在彻底验证了 php 中安装并启用了curl并且apache正在调用正确的php版本之后,我终于意识到问题出在代码本身上。 不是语法,而是代码中显然存在导致错误的不可见字符。 重新输入相同的代码后,它起作用了。

<?php
// API
$url = 'https://api.openai.com/v1/embeddings';

// Create a new cURL resource
$ch = curl_init($url);
?>

如果有人知道检测文本文件中这些字符的方法,请在评论中留下该信息。 谢谢!

© www.soinside.com 2019 - 2024. All rights reserved.