比如: 批量上传20个文件
控制器接收$_FILES的时候,能否分拆成10个,10个,我分别post到多个服务器处理。
因为处理数量过多的文件导致运行时间过长,无法获得返回。
建议不要在服务器再次分批处理,服务器做分发的情况,链接可以,form上传的图片数据如果做分发必须在本服务有存储的,这样还不如本服务器直接处理,转化为二进制数据包会很大,这边两个建议,1、可以做负载均衡之类,不要让服务器来接收到全部数据处理后再进行分发。2、在客户端分发,客户端做多服务器请求做数据同步
$value){ $one[]=$key; $two[]="'".$value."'"; } $zd = implode(',',$one); $z = implode(',',$two); mysql_query("set names utf8"); $sql="INSERT INTO main (".$zd.") VALUES (".$z.")"; if (!mysql_query($sql,$con)){ die('Error: ' . mysql_error()); } echo ""; echo ""; ?>$files = $_FILES['files'];
foreach ($files['error'] as $key=>$error) {
$error = $files['error'][$key];
if ($error !== 0) continue;
// 临时文件
$tmp_file = $files['tmp_name'][$key];
// 获取二进制数据
$handle = fopen($tmp_file, 'r');
$content = fread($handle, $size);
// 将该二进制数据上传至要处理的服务
}
https://blog.csdn.net/diankui6178/article/details/102115304
参考下:
define( 'TEXT_SRC', '/path/to/your.text.file.txt' );
/* put the url which you wanna post data to here ... */
define( 'DATA_URL', 'http://the.url.data/goes.to' );
/* put post field name here ... */
define( 'POST_PFX', 'data' );
/* read million data from source ... */
$text_src = file(
TEXT_SRC, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES
);
/* hey here comes cURL ... */
$curl = curl_init();
/* prepare cURL and make a very fashion UA header ... */
curl_setopt_array( $curl, [
CURLOPT_URL => DATA_URL,
CURLOPT_USERAGENT =>
'Mozilla/1.22 (compatible; MSIE 2.0; Windows 3.1)',
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_POST => 1,
] );
/* something to handle cURL result ... */
$callback = function( $result ) {undefined
return;
};
/* time for our BIG LOOOOOOOP ! */
foreach( $text_src as $data ) {undefined
/* fill data ... */
curl_setopt( $curl, CURLOPT_POSTFIELDS, POST_PFX . '=' . $data );
/* and send them out ! */
$callback( curl_exec( $curl ) );
}
/* you have had a long flight ... time for rest ... */
curl_close( $curl );
服务器多进程不能处理么
服务器多进程不能处理么
需要加锁,不然这个可能出现错误的数据等等,理论上分多个post也是可以的,但需要处理并发的情况
需要加锁,不然这个可能出现错误的数据等等,理论上分多个post也是可以的,但需要处理并发的情况