Reputation: 29
I keep getting this curl error
Warning curl_setopt() expects parameter 2 to be long, string given
curl_setopt() expects parameter 2 to be long, string given in /var/www/mbl.domain.com/html/admin/functions/api/jobs_send.php at 706
Code:
$request = urlencode($xml);
$url = 'http://integrated.com/1.3';
$query = 'token=' . $token . '&';
$query .= 'idomain=' . $idomain . '&';
$query .= 'cdomain=' . $cdomain . '&';
$query .= 'request=' . $request;
if(!$ch = curl_init()){
die("Could not init cURL session.\n");
}
curl_setopt($ch, CURLOPT_ENCODING , "gzip"); // we are making our api call fast by 70%
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDSIZE, sizeof($query));
curl_setopt($ch, CURLOPT_POSTFIELDS, $query);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT ,0);
curl_setopt($ch, CURLOPT_TIMEOUT, 40); //timeout in seconds
curl_setopt($ch, CURLOPT_SSLVERSION, 3);
$result = curl_exec($ch);
curl_close($ch);
$xmlObj = simplexml_load_string($result,"SimpleXMLElement", LIBXML_NOCDATA);
line 706:
curl_setopt($ch, CURLOPT_POSTFIELDSIZE, sizeof($query));
How can i solve this?
Upvotes: 2
Views: 3168
Reputation: 5668
There is no such option as CURLOPT_POSTFIELDSIZE
in PHP. That is automatically set for you internally when you specify CURLOPT_POSTFIELDS
.
You are getting the error you are because PHP sees the undefined constant CURLOPT_POSTFIELDSIZE
, turns it into a string ("CURLOPT_POSTFIELDSIZE"
), and passes that into the function. This causes the error, because all the CURLOPT_*
constants are actually integers. (The undefined constant to string conversion will raise a warning; if you are logging warnings/errors, it should show up in your logs.)
Also: not causing your problem, but an error nonetheless: sizeof($string) === 1
. sizeof
is an alias for count
, which returns 1
for scalars. For a string's length, you want to use strlen($string)
instead.
Upvotes: 3