The undefined curl function in console (WampServer)


Stupid stupid me. On Windows/WampServer, I’ve always had this problem when working with PHP code that can run in the console and using cURL methods..

PHP Fatal error:  Call to undefined function curl_init() in D:\Shiki\github\yii-clockwerk\test-app\CurlHelper.php on line 90
Fatal error: Call to undefined function curl_init() in D:\Shiki\github\yii-clockwerk\test-app\CurlHelper.php on line 90

It (cURL) works in the browser but not when in console. I didn’t think that it was this simple to fix. The PHP CLI uses a different config file (php.ini) compared to the one used by WampServer/Apache. You can see the location of the config file being used by typing:

$ php --ini

Result:

Configuration File (php.ini) Path: C:\Windows
Loaded Configuration File:         C:\wamp\bin\php\php5.3.0\php.ini
Scan for additional .ini files in: (none)
Additional .ini files parsed:      (none)

You can then fix the curl problem by enabling it in the php.ini file being used. Make sure this is not commented out:

extension=php_curl.dll