Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

$length argument for fpassthru #9673

Open
divinity76 opened this issue Oct 5, 2022 · 1 comment
Open

$length argument for fpassthru #9673

divinity76 opened this issue Oct 5, 2022 · 1 comment

Comments

@divinity76
Copy link
Contributor

Description

would be nice to have a ?int $length=null for fpassthru.

currently, implementing HTTP range requests seems to be a pain: readfile() isn't suitable because it has neither a $offset nor a $length argument, and fpassthru isn't suitable either because it doesn't have a $length argument, so you'll have to resort to a fread()+echo loop.

It would be easier and faster to implement HTTP range support if fpassthru had a $length argument.

@damianwadley
Copy link
Member

Have you seen stream_copy_to_stream?

$input = fopen("/path/to/file.ext", "rb");
$output = fopen("php://output", "wb");
stream_copy_to_stream($input, $output, $length, $offset);
fclose($output);
fclose($input);

Not a complete solution but it's better than an fread loop.

nielsdos added a commit to nielsdos/php-src that referenced this issue Jan 30, 2023
This implements an optional $length argument to fpassthru,
SplFileObject::fpassthru and gzpassthru for partially copying the file
to the output. The behaviour of this new argument has the same behaviour
as the $length argument of stream_copy_to_stream.

Internally, a new macro and function is introduced:
_php_stream_passthru_with_length. _php_stream_passthru now calls the new
function to perform its tasks without introducing a BC break internally.

This unfortunately has one BC break: classes overriding SplFileObject
must update the method signature of fpassthru to add the new argument.
nielsdos added a commit to nielsdos/php-src that referenced this issue Jan 30, 2023
This implements an optional $length argument to fpassthru,
SplFileObject::fpassthru and gzpassthru for partially copying the file
to the output. The behaviour of this new argument has the same behaviour
as the $length argument of stream_copy_to_stream.

Internally, a new macro and function is introduced:
_php_stream_passthru_with_length. _php_stream_passthru now calls the new
function to perform its tasks without introducing a BC break internally.

This unfortunately has one BC break: classes overriding SplFileObject
must update the method signature of fpassthru to add the new argument.
nielsdos added a commit to nielsdos/php-src that referenced this issue Jan 31, 2023
This implements an optional $length argument to fpassthru,
SplFileObject::fpassthru and gzpassthru for partially copying the file
to the output. The behaviour of this new argument has the same behaviour
as the $length argument of stream_copy_to_stream.

Internally, a new macro and function is introduced:
_php_stream_passthru_with_length. _php_stream_passthru now calls the new
function to perform its tasks without introducing a BC break internally.

This unfortunately has one BC break: classes overriding SplFileObject
must update the method signature of fpassthru to add the new argument.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants