Skip to content

Conversation

@ndossche
Copy link
Member

@ndossche ndossche commented Nov 8, 2025

Needs more testing, but shows the general idea.

Small PoC bench:

<?php
class MyStream {
    public $context;

    public function stream_open(
        string $path,
        string $mode,
        int $options,
        ?string &$opened_path
    ): bool {
        // debug_print_backtrace();
        return true;
    }

    public function stream_read(int $count): string|false {
        return 'abc';
    }

    public function stream_eof(): bool {
        return false;
    }
}

stream_wrapper_register('my', MyStream::class);

$f = fopen('my://', 'r');
for ($i = 0; $i < 1000000; $i++)
    fread($f, 4096);

On my i7-4790:

  Time (mean ± σ):     135.6 ms ±   3.9 ms    [User: 132.8 ms, System: 2.3 ms]
  Range (min … max):   132.8 ms … 151.6 ms    22 runs
 
  Warning: Statistical outliers were detected. Consider re-running this benchmark on a quiet system without any interferences from other programs. It might help to use the '--warmup' or '--prepare' options.
 
Benchmark 2: ./sapi/cli/php_old x.php
  Time (mean ± σ):     234.3 ms ±   5.7 ms    [User: 231.4 ms, System: 2.2 ms]
  Range (min … max):   229.4 ms … 249.6 ms    12 runs
 
Summary
  ./sapi/cli/php x.php ran
    1.73 ± 0.07 times faster than ./sapi/cli/php_old x.php

@ndossche ndossche requested a review from bukka as a code owner November 8, 2025 22:00
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

Successfully merging this pull request may close these issues.

1 participant