1

Running on Centos 7 system. phpinfo() says curl is enabled, but when I run this code:

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

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

I get error: PHP Fatal error:

Uncaught Error: Call to undefined function curl_init()

If I try to install it says it's already installed:

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

All out of answers. What can I try from here? Why is curl not executing?

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

In /etc/php.d/20-curl.ini:

extension=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      
2
  • "phpinfo() says curl is enabled" - executed from within your script? Or from a different context such as CLI - which might use a different php.ini? Commented Jan 27, 2023 at 9:00
  • php -i from command line: curl cURL support => enabled cURL Information => 7.29.0 Commented Jan 28, 2023 at 9:22

1 Answer 1

0

Corruption of the file turned out to be the culprit.

At any rate, after exhaustively verifying that curl was installed and enabled in php and apache was calling the correct php version, I finally realized the problem was in the code itself. Not the syntax, but apparently there were invisible characters in the code that were causing the error. After re-entering the same code, it worked.

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

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

If anyone knows of a way to detect these characters in a text file, please leave that info in the comments. Thanks!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.