if(isset($cfg['postfields']) && $cfg['postfields'] === 0) {
$cfg['post'] = 1;
$cfg['postfields'] = '';
}elseif ( isset($cfg['post']) && !empty($cfg['post']) && !isset($cfg['postfields']) ) {
$post = /*is_array($cfg['post']) ? http_build_query($cfg['post']) : */$cfg['post'];
$cfg['post'] = 1;
$cfg['postfields'] = $post;
}
//下载文件使用
if(isset($cfg['to_file']) && $cfg['to_file']){//to_file
$f = is_bool($cfg['to_file'])?($this->_tmpPath.uniqid().mt_rand(100,999)):$cfg['to_file'];
$fp = fopen ($f, 'w+');
unset($cfg['returntransfer']);
$cfg['file'] = $fp;
$this->_downloadToFiles[$idx] = [$f,$fp];//记录该任务存储路径,留完成后关闭 和重试的时候使用
}elseif ( isset($this->_downloadToFiles[$idx]) && $this->_downloadToFiles[$idx][0] ){
//重试的时候 $cfg['to_file']已经被删除
$fp = fopen ($this->_downloadToFiles[$idx][0] , 'w+');
$this->_downloadToFiles[$idx][1] = $fp;
$cfg['file'] = $fp;
}
if(isset($cfg['@transfer']) && !empty($cfg['@transfer'])){//走中转代理包装
$url = $cfg['@transfer'];
unset($cfg['@transfer']);
$cfg = [
'post'=>1,
'postfields'=>http_build_query(['cfg'=>json_encode($cfg)]),
'url'=>$url
];
}
$this->_fire('item_before_request',[$this->_decodeId($idx),$cfg]);
$conn = curl_init();
foreach ($cfg as $k => $v) {
$k = 'CURLOPT_' . strtoupper($k);
if (defined($k)) {
curl_setopt($conn, constant($k), $v);
}
}
return $conn;
}`