note 88520 modified in function.copy by danbrown
| From: | danbrown@php.net | Date: | Tue, 27 Jan 2009 19:54:45 +0000 |
| Subject: | note 88520 modified in function.copy by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-149862@lists.php.net to get a copy of this message | ||
When I recently had to copy a few millions of small files (< 1kb) from one NAS to another and for
some reasons had to do that file by file I compared the following function with copy($src, $dest)
and shell_exec("cp -r $src $dest").
Surprisingly stream_copy seamed to be slightly faster (at least in this specific context).
<?php
function stream_copy($src, $dest)
{
$fsrc = fopen($src,'r');
$fdest = fopen($dest,'w+');
$len = stream_copy_to_stream($fsrc,$fdest);
fclose($fsrc);
fclose($fdest);
return $len;
}
?>
--was--
When I recently had to copy a few millions of small files (< 1kb) from one NAS to another and for
some reasons had to do that file by file I compared the following function with copy($src, $dest)
and shell_exec("cp -r $src $dest").
Surprisingly stream_copy seamed to be slightly faster (at least in this specific context).
function stream_copy($src, $dest)
{
$fsrc = fopen($src,'r');
$fdest = fopen($dest,'w+');
$len = stream_copy_to_stream($fsrc,$fdest);
fclose($fsrc);
fclose($fdest);
return $len;
}
http://php.net/manual/en/function.copy.php