mirror of
https://github.com/Piwigo/Piwigo.git
synced 2025-04-27 11:49:56 +03:00
merge r3239 from branch 2.0 to trunk
bug 949 fixed: to avoid memory limit on server side, base64 encode chunks one by one on client side and base64 decode chunks one by one on server side. git-svn-id: http://piwigo.org/svn/trunk@3240 68402e56-0260-453c-a942-63ccdbb3a9ee
This commit is contained in:
parent
77721e034b
commit
3c27690c87
2 changed files with 20 additions and 11 deletions
|
@ -923,9 +923,11 @@ function ws_images_add_chunk($params, &$service)
|
||||||
$params['position']
|
$params['position']
|
||||||
);
|
);
|
||||||
|
|
||||||
|
ws_logfile('[ws_images_add_chunk] data length : '.strlen($params['data']));
|
||||||
|
|
||||||
$bytes_written = file_put_contents(
|
$bytes_written = file_put_contents(
|
||||||
$upload_dir.'/'.$filename,
|
$upload_dir.'/'.$filename,
|
||||||
$params['data']
|
base64_decode($params['data'])
|
||||||
);
|
);
|
||||||
|
|
||||||
if (false === $bytes_written) {
|
if (false === $bytes_written) {
|
||||||
|
@ -958,17 +960,24 @@ function merge_chunks($output_filepath, $original_sum, $type)
|
||||||
}
|
}
|
||||||
|
|
||||||
sort($chunks);
|
sort($chunks);
|
||||||
|
|
||||||
|
ws_logfile('[merge_chunks] memory_get_usage before loading chunks: '.memory_get_usage());
|
||||||
|
|
||||||
$string = null;
|
foreach ($chunks as $chunk)
|
||||||
foreach ($chunks as $chunk) {
|
{
|
||||||
$string.= file_get_contents($chunk);
|
$string = file_get_contents($chunk);
|
||||||
|
|
||||||
|
ws_logfile('[merge_chunks] memory_get_usage on chunk '.++$i.': '.memory_get_usage());
|
||||||
|
|
||||||
|
if (!file_put_contents($output_filepath, $string, FILE_APPEND))
|
||||||
|
{
|
||||||
|
return new PwgError(500, 'error while writting chunks for '.$output_filepath);
|
||||||
|
}
|
||||||
|
|
||||||
unlink($chunk);
|
unlink($chunk);
|
||||||
}
|
}
|
||||||
if (!file_put_contents($output_filepath, base64_decode($string)))
|
|
||||||
{
|
ws_logfile('[merge_chunks] memory_get_usage after loading chunks: '.memory_get_usage());
|
||||||
return new PwgError(500, 'error while merging chunks for '.$output_filepath);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function ws_images_add($params, &$service)
|
function ws_images_add($params, &$service)
|
||||||
|
|
|
@ -255,7 +255,7 @@ sub pwg_ws_get_query {
|
||||||
sub send_chunks {
|
sub send_chunks {
|
||||||
my %params = @_;
|
my %params = @_;
|
||||||
|
|
||||||
my $content = encode_base64(read_file($params{filepath}));
|
my $content = read_file($params{filepath});
|
||||||
my $content_length = length($content);
|
my $content_length = length($content);
|
||||||
my $nb_chunks = ceil($content_length / $conf{chunk_size});
|
my $nb_chunks = ceil($content_length / $conf{chunk_size});
|
||||||
|
|
||||||
|
@ -273,7 +273,7 @@ sub send_chunks {
|
||||||
$conf{base_url}.'/ws.php?format=json',
|
$conf{base_url}.'/ws.php?format=json',
|
||||||
{
|
{
|
||||||
method => 'pwg.images.addChunk',
|
method => 'pwg.images.addChunk',
|
||||||
data => $chunk,
|
data => encode_base64($chunk),
|
||||||
original_sum => $params{original_sum},
|
original_sum => $params{original_sum},
|
||||||
position => $chunk_id,
|
position => $chunk_id,
|
||||||
type => $params{type},
|
type => $params{type},
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue