16

I am making a cURL request via Kohana 3.2 but I get the following error when it tries to access CURLOPT_POST constant:

Use of undefined constant CURLOPT_POST - assumed 'CURLOPT_POST'

From Kohana 3.2 system/classes/kohana/request/client/curl.php

public function _set_curl_request_method(Request $request, array $options)
{
    switch ($request->method()) {
        case Request::POST:
            $options[CURLOPT_POST] = TRUE;
            break;
        case Request::PUT:
            $options[CURLOPT_PUT] = TRUE;
            break;
        default:
            $options[CURLOPT_CUSTOMREQUEST] = $request->method();
            break;
    }
    return $options;
}

My application code:

$request = Request::factory($uri);
$request->query('key', $key);
$request->post($params);
$request->method(Request::POST);

// fails here
$response = $request->execute();

I have tested that curl is active as an extension using:

if (in_array  ('curl', get_loaded_extensions()))
{
    echo '1';
}
else
{
    echo '0';
}

What is the problem here? I am using Windows 7, PHP 5.4.12, and Apache 2.4.

xylar
  • 7,433
  • 17
  • 55
  • 100
  • Can you show the piece of code where you're actually using `CURLOPT_POST`? – kero Mar 28 '14 at 13:01
  • Added the code to my post – xylar Mar 28 '14 at 13:04
  • Do you already have an acutal call to any of the curl function in your script? One that would make php bail out with `undefined function curl_....` if the curl extension isn't available? If not (or unsure) better double-check via phpinfo(), extension_loaded('curl'), ... – VolkerK Mar 28 '14 at 13:07
  • No, can you show the code where you making the actual request? The code you've posted is a snippet from the Kohana library. Are you making the request via the request factory? if so, how? show that part of the code.. e.g. `$request = Request::factory($url)->method('POST')->post('key', 'value');` – Latheesan Mar 28 '14 at 13:08
  • I know it's early and all, but isn't this expected behavior from an unquoted array key? – Mattt Mar 28 '14 at 13:15
  • @MattThompson This is how you set curl options ([see manual](http://us1.php.net/manual/en/function.curl-setopt-array.php)) – kero Mar 28 '14 at 13:18
  • @Matt : it's a constant defined by the curl extension, see http://docs.php.net/constants – VolkerK Mar 28 '14 at 13:19
  • @LatheesanKanes added application code – xylar Mar 28 '14 at 13:21
  • but in this context it is being used as an array key for an array created by the kohana library... it is not being used directly to set the option. I understand how curl works. – Mattt Mar 28 '14 at 13:23
  • @MattThompson See my link, they use it as an unquoted key in the manual as well – kero Mar 28 '14 at 13:41
  • @Matt : You are confusing string literals and constants, http://docs.php.net/manual/en/language.types.array says "Note: This does not mean to always quote the key. Do not quote keys which are constants or variables, as this will prevent PHP from interpreting them." – VolkerK Mar 28 '14 at 14:15
  • @VolkerK - I understand that part, from looking at it, I was just confused as to whether this $options array was being passed directly as a parameter to curl or if it was an array of available curl settings within kohana. I hope that makes sense. I implicitly understand the difference between string keys and constants, I just misinterpreted the code posted I guess. – Mattt Mar 28 '14 at 15:24

2 Answers2

18

First, let's check php-curl has been installed on your server by

aptitude search php-curl

or aptitude search php5.6-curl

if that hasn't been installed yet, let's install it by

sudo apt-get install php5.6-curl
Viet Anh Do
  • 449
  • 5
  • 6
  • This will **not** work, as the question-asker specifically states that they have an older version of PHP (5.4.12), which would be incompatible with `php5.6-curl`. Please carefully read questions before providing answers. Also, this question was asked 2 years ago, and already had an accepted solution. Please try to avoid 'bumping' questions to the top by providing answers to them, unless the question was not already marked as resolved, or you found a dramatically better alternative approach to the problem :) – Obsidian Age Feb 08 '17 at 02:10
5

I noticed extension=php_curl.dll was commented out in C:\wamp\bin\php\php5.4.12\php.ini but active via C:\wamp\bin\apache\Apache2.4.4\bin\php.ini.

I found that uncommenting the line in C:\wamp\bin\php\php5.4.12\php.ini fixed my issue.

xylar
  • 7,433
  • 17
  • 55
  • 100