[英]Warning curl_setopt() expects parameter 2 to be long, string given
I keep getting this curl error 我不断收到此卷曲错误
Warning curl_setopt() expects parameter 2 to be long, string given
警告curl_setopt()期望参数2长,给定字符串
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
curl_setopt()期望参数2长,字符串在/var/www/mbl.domain.com/html/admin/functions/api/jobs_send.php中以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: 706行:
curl_setopt($ch, CURLOPT_POSTFIELDSIZE, sizeof($query));
How can i solve this? 我该如何解决?
There is no such option as CURLOPT_POSTFIELDSIZE
in PHP. 在PHP中没有
CURLOPT_POSTFIELDSIZE
这样的选项。 That is automatically set for you internally when you specify CURLOPT_POSTFIELDS
. 当您指定
CURLOPT_POSTFIELDS
时,将在内部自动为您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. 您正在得到错误,因为PHP看到未定义的常量
CURLOPT_POSTFIELDSIZE
,将其转换为字符串( "CURLOPT_POSTFIELDSIZE"
),并将其传递给函数。 This causes the error, because all the CURLOPT_*
constants are actually integers. 这会导致错误,因为所有
CURLOPT_*
常量实际上都是整数。 (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($string) === 1
。 sizeof
is an alias for count
, which returns 1
for scalars. sizeof
是count
的别名,标量返回1
。 For a string's length, you want to use strlen($string)
instead. 对于字符串的长度,您想改用
strlen($string)
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.