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

Uses more memory than native PHP stream filters when call stream_copy_too_stream() #54

Open
guanguans opened this issue Oct 21, 2024 · 0 comments

Comments

@guanguans
Copy link

guanguans commented Oct 21, 2024

File size: 106.38 MB, Time: 00:00.175, Memory: 333.17 MB

<?php

declare(strict_types=1);

use SebastianBergmann\Timer\ResourceUsageFormatter;
use SebastianBergmann\Timer\Timer;

require __DIR__.'/vendor/autoload.php';

$timer = new Timer;
$timer->start();
$resourceRead = fopen($file = '/.../laravel-2024-09-12.log', 'rb');
$resourceWrite = fopen('/.../laravel-2024-09-12_copy.log', 'wb');
Clue\StreamFilter\append($resourceWrite, strtoupper(...));
// stream_filter_append($resourceWrite, 'string.toupper');
stream_copy_to_stream($resourceRead, $resourceWrite);
echo sprintf('File size: %.2f MB, ',
    filesize($file) / 1024 / 1024), (new ResourceUsageFormatter)->resourceUsage($timer->stop());

// Output:
// File size: 106.38 MB, Time: 00:00.175, Memory: 333.17 MB

File size: 106.38 MB, Time: 00:00.089, Memory: 120.39 MB(using string.toupper)

<?php

declare(strict_types=1);

use SebastianBergmann\Timer\ResourceUsageFormatter;
use SebastianBergmann\Timer\Timer;

require __DIR__.'/vendor/autoload.php';

$timer = new Timer;
$timer->start();
$resourceRead = fopen($file = '/.../laravel-2024-09-12.log', 'rb');
$resourceWrite = fopen('/.../laravel-2024-09-12_copy.log', 'wb');
// Clue\StreamFilter\append($resourceWrite, strtoupper(...));
stream_filter_append($resourceWrite, 'string.toupper');
stream_copy_to_stream($resourceRead, $resourceWrite);
echo sprintf('File size: %.2f MB, ',
    filesize($file) / 1024 / 1024), (new ResourceUsageFormatter)->resourceUsage($timer->stop());

// Output:
// File size: 106.38 MB, Time: 00:00.089, Memory: 120.39 MB
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant