Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7616637
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T02:56:15+00:00 2026-05-31T02:56:15+00:00

I am looking for the best way to pipe data from one stream to

  • 0

I am looking for the best way to pipe data from one stream to another without having to deal with buffering myself. Basically the equivalent of the node.js stream.pipe function.

There is stream_copy_to_stream, but according to the comments on the manual page it is quite a memory hog (possibly reading the whole stream into memory?).

Of course I could do something like this:

$fh = fopen('filename.txt', 'rb');
$out = STDOUT;
while (!feof($fh)) {
    $bytes = 1024;
    fwrite(STDOUT, fread($fh, $bytes), $bytes);
}
fclose($fh);

But I’m hoping there is an easier API to accomplish this, without having to do the buffering myself.

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T02:56:16+00:00Added an answer on May 31, 2026 at 2:56 am

    I downloaded the source code of PHP 5.4.0 and looked up stream_copy_to_stream (streams.c line 1419). It looks reasonable in my opinion.

    First it tries to memory-map the source stream, and write the whole thing to the destination in one go without using an intermediate buffer.

    If memory mapping is not possible, then it uses an internal buffer (8192 bytes, see CHUNK_SIZE in php_streams_int.h line 49) to shuffle the data from the source to the destination.

    Either the manual comment is wrong, or the developers have improved the function since it was first written. I would give it another look.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm looking for the best way to select numbers directly from an in clause.
I'm looking for the best way of loading formatted data in VBA. I’ve spent
I am looking for the best way of extracting a 2D sub-matrix from a
Looking for the best way to determine if a URI exists in VB.NET without
I am looking for the best way to store data in a game. Currently
Looking for the best way to do ownership validation in a Rails model without
I am looking for a best way to trigger windows application automation from Java
I'm looking for the best way to detect more than one finger on the
I'm looking for the best way to take a datetime string from MySQL, explode
I am having a bunch of photos and I'm looking for best way of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.