Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
main/streams/streams: use copy_file_range() on Linux (#8413)
copy_file_range() is a Linux-specific system call which allows efficient copying between two file descriptors, eliminating the need to transfer data from the kernel to userspace and back. For networking file systems like NFS and Ceph, it even eliminates copying data to the client, and local filesystems like Btrfs and XFS can create shared extents.
- Loading branch information
1 parent
4ec92c6
commit fa6d97d
Showing
4 changed files
with
161 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
ext/standard/tests/file/stream_copy_to_stream_interleaved.phpt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
--TEST-- | ||
stream_copy_to_stream() tests with interleaved read/write calls | ||
--FILE-- | ||
<?php | ||
define('WIN', substr(PHP_OS, 0, 3) == 'WIN'); | ||
|
||
$initial_file = __DIR__.'/bug38086.txt'; | ||
$new_file = __DIR__.'/stream_copy_to_stream_interleaved.txt'; | ||
|
||
$src = fopen($initial_file, 'r'); | ||
|
||
$dest = fopen($new_file, 'w'); | ||
|
||
var_dump(fread($src, 10)); | ||
var_dump(fwrite($dest, "foo")); | ||
var_dump(stream_copy_to_stream($src, $dest, 10)); | ||
var_dump(ftell($src)); | ||
var_dump(ftell($dest)); | ||
var_dump(fread($src, 10)); | ||
var_dump(fwrite($dest, "bar")); | ||
var_dump(stream_copy_to_stream($src, $dest, 10)); | ||
var_dump(ftell($src)); | ||
var_dump(ftell($dest)); | ||
fclose($src); fclose($dest); | ||
|
||
if (WIN) { | ||
var_dump(str_replace("\r\n","\n", file_get_contents($new_file))); | ||
} else { | ||
var_dump(file_get_contents($new_file)); | ||
} | ||
unlink($new_file); | ||
|
||
echo "Done\n"; | ||
?> | ||
--EXPECTF-- | ||
string(10) "Another da" | ||
int(3) | ||
int(10) | ||
int(20) | ||
int(13) | ||
string(10) " pains of " | ||
int(3) | ||
int(10) | ||
int(40) | ||
int(26) | ||
string(26) "fooy | ||
When thebarlife won't" | ||
Done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters