php - 通过 curl 发送较大文件的问题
问题描述
整个下午,
通过 curl 发送大文件时遇到一些问题,我们可以发送第一个 5mb 的测试文件,但第二个测试文件是 34mb 并且不发送。我们增加了发送和接收服务器上的帖子和最大上传大小,但仍然没有乐趣。
这是发送脚本:
function send_files($directory, $file, $dir_parts) {
$url = 'https://test.com/App_processing/transfer_videos';
$handle = fopen($directory."video.mp4", "r");
$stats = fstat($handle);
$data = stream_get_contents($handle);
$payload = array(
'file' => base64_encode($data),
'parts' => $dir_parts
);
$postfields = array( serialize( $payload ) );
$ssl = strstr($url, '://', true);
$port = ($ssl == 'https') ? 443 : 80;
$verify_ssl = false;
$ch = curl_init();
$curlConfig = array(
CURLOPT_PORT => $port,
CURLOPT_URL => $url,
CURLOPT_SSL_VERIFYPEER => $verify_ssl,
CURLOPT_FORBID_REUSE => true,
CURLOPT_FRESH_CONNECT => true,
CURLOPT_FAILONERROR => false,
CURLOPT_VERBOSE => true,
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_COOKIESESSION => true,
CURLOPT_POSTFIELDS => $postfields,
);
$headers = null;
$apikey = 'testAPIkey';
$headers = array(
"apikey: ".$apikey
);
$curlConfig[CURLOPT_HTTPHEADER] = $headers;
curl_setopt_array( $ch, $curlConfig );
$response = curl_exec( $ch );
}
接收脚本:
public function transfer_videos() {
$return_arr = array();
ini_set('max_execution_time', '999');
ini_set('memory_limit', '512M');
ini_set('post_max_size', '512M');
if(count($this->post_data) > 0) {
$image = $this->post_data['file'];
$file = base64_decode($image);
$filename = $this->post_data['parts'][2];
$return_arr = array();
$office_path = $this->config->item('_path') . '_videos/';
$path = $o_path.$this->post_data['parts'][0]."/".$this->post_data['parts'][1]."/";
$name = $filename;
if( !is_dir( $path ) ) {
mkdir( $path, 0750, true );
}
try {
$return_arr = file_put_contents($path.$name, $file);
} catch (Exception $e) {
$this->curl_helper->error($path.$name, "failed to upload file");
}
}
echo serialize($return_arr);
}
我们得到的当前错误是:
Recv failure: Connection reset by peer
我们到底做错了什么?
解决方案
推荐阅读
- prolog - Prolog FindAll 具有一系列特定值
- list - 这是什么意思?“nums[-1] = nums[n] = -∞”
- context-free-grammar - 空字符串在歧义语法中的作用?
- r - R-使用sqldf加入数据框时列太多
- javascript - 自定义字体 JavaScript
- typescript - @emotion 样式文件的 @typescript-eslint/naming-convention 自定义配置
- python - 用户点击后如何更改选项菜单的值?
- hex - 如何使用 Linux 将 ASCII 数字 0 - 9 的文件转换为 base 8 HEX?
- python - 终止线程和/或调度程序
- python - 仅将一个字典合并到另一个具有公共字段的字典中