Home  >  Article  >  Backend Development  >  Solution to the problem of Call to undefined function curl_init() when running PHP

Solution to the problem of Call to undefined function curl_init() when running PHP

高洛峰
高洛峰Original
2016-12-23 15:04:242309browse

I downloaded a PHP program example from the Internet that simulates logging into the discuz forum. During the trial run, the error message "Call to undefined function curl_init" appeared. There is no defined function, that is, PHP has not yet turned on support for the curl_init function. After searching on Google, I finally solved it. The method is as follows:

System environment, WIN2003 IIS6, PHP version 5.2.12
After installing PHP, execute a statement like $ch = curl_init();, Call to undefined function curl_init appears () error message.

The solution is as follows:

1. Find extension=php_curl.dll in php.ini and remove the previous one. php.ini is usually under c:windows.

2. Find extension_dir = "ext" in php.ini, remove the previous;, and change it to extension_dir = "C:php5ext".
"C:php5ext" is just an example, that is, the path pointed to by the extension must be copied to system32.

4. Then restart the computer and the fault is solved.

Note: I don’t know why in PHP version 5.2.8, this method can’t solve it, so I changed it to 5.2.12 to solve it.


Take php+apache under windows as an example.

First, open php.ini, find "extension=php_curl.dll", then remove the ";" comment in front and restart apache.

If this kind of problem still occurs, first check which directory the extension_dir value of php.ini is, and check whether there is php_curl.dll in that directory. If not, please download php_curl.dll, and then put libeay32.dll and libeay32.dll in the php directory. Copy ssleay32.dll to c:windowssystem32, restart apache, OK!

When running php under Ubuntu, it always prompts Call to undefined function curl_init(). The reason is not fixed: php5-curl

For curl-related content, please see: http://packages.ubuntu.com/zh-cn/ intrepid/php5-curl

CURL is a library for getting files from FTP, GOPHER, HTTP server.

PHP5 is an HTML-embedded scripting language. Much of its syntax is borrowed from C, Java and Perl with a couple of unique PHP-specific features thrown in. The goal of the language is to allow web developers to write dinamically generated pages quickly. This version of PHP5 was built with the Suhosin patch.

H1>

(PHP 4 >= 4.0.2 )

curl_init -- Initialize a CURL session

Description

int curl_init ([string url])

curl_init() function will initialize a new session and return a CURL handle for curl_setopt(), curl_exec(), and curl_close() function is used. If the optional parameter is provided, the CURLOPT_URL option will be set to the value of this parameter. You can set it manually using the curl_setopt() function.
Example 1. Initialize a new CURL session and retrieve a web page

$ch = curl_init();

curl_setopt ($ch, CURLOPT_URL, "http://www.zend.com/ ");
curl_setopt ($ch, CURLOPT_HEADER, 0);

curl_exec ($ch);

curl_close ($ch);
?>


See: curl_close(), curl_setopt()

more For solutions to the problem of Call to undefined function curl_init() when running PHP, please pay attention to the PHP Chinese website for related articles!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn