本文介绍了Laravel队列在作业分配时出现卷曲错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用建立一些交易机器人。当我尝试这样(从测试控制器)发出请求时:
I'm using bitmex library to build some trading bot. When i try to make request like this (from test controller):
$this->api->createOrder(....);
一切正常-api创建了订单。
Everything works fine - api creates an order.
但是,当我尝试使用队列作业(数据库驱动程序)发出此请求时,出现错误:
But, when i try to make this request with queue job(database driver) i got error:
队列cUrl实例中的任何api请求都返回0代替资源和此错误。可能是什么问题?
Any api request from queue cUrl instance return 0 instead resource and this error. What could be the problem?
P.S。库中的卷曲方法:
P.S. Curl method from library:
private function authQuery($data) {
$method = $data['method'];
$function = $data['function'];
if($method == "GET" || $method == "POST" || $method == "PUT") {
$params = http_build_query($data['params']);
}
elseif($method == "DELETE") {
$params = json_encode($data['params']);
}
$path = self::API_PATH . $function;
$url = self::API_URL . self::API_PATH . $function;
if($method == "GET" && count($data['params']) >= 1) {
$url .= "?" . $params;
$path .= "?" . $params;
}
$nonce = $this->generateNonce();
if($method == "GET") {
$post = "";
}
else {
$post = $params;
}
$sign = hash_hmac('sha256', $method.$path.$nonce.$post, $this->apiSecret);
$headers = array();
$headers[] = "api-signature: $sign";
$headers[] = "api-key: {$this->apiKey}";
$headers[] = "api-nonce: $nonce";
$headers[] = 'Connection: Keep-Alive';
$headers[] = 'Keep-Alive: 90';
curl_reset($this->ch);
curl_setopt($this->ch, CURLOPT_URL, $url);
if($data['method'] == "POST") {
curl_setopt($this->ch, CURLOPT_POST, true);
curl_setopt($this->ch, CURLOPT_POSTFIELDS, $post);
}
if($data['method'] == "DELETE") {
curl_setopt($this->ch, CURLOPT_CUSTOMREQUEST, "DELETE");
curl_setopt($this->ch, CURLOPT_POSTFIELDS, $post);
$headers[] = 'X-HTTP-Method-Override: DELETE';
}
if($data['method'] == "PUT") {
curl_setopt($this->ch, CURLOPT_CUSTOMREQUEST, "PUT");
//curl_setopt($this->ch, CURLOPT_PUT, true);
curl_setopt($this->ch, CURLOPT_POSTFIELDS, $post);
$headers[] = 'X-HTTP-Method-Override: PUT';
}
curl_setopt($this->ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($this->ch, CURLOPT_SSL_VERIFYPEER , false);
curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, true);
$return = curl_exec($this->ch);
if(!$return) {
$this->curlError();
$this->error = true;
return false;
}
$return = json_decode($return,true);
if(isset($return['error'])) {
$this->platformError($return);
$this->error = true;
return false;
}
$this->error = false;
$this->errorCode = false;
$this->errorMessage = false;
return $return;
}
推荐答案
您需要使用此方法初始化卷曲
You need to initialize the curl by using this method
$this->ch = curl_init();
curl_setopt($this->ch, CURLOPT_URL, $url);
这篇关于Laravel队列在作业分配时出现卷曲错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!