Skip to content

tests/benchmark/benchmark.php failed when specifying a non-exist output csv file #1068

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

Open
WangYihang opened this issue Mar 17, 2025 · 0 comments

Comments

@WangYihang
Copy link

Version(s) affected

2.6

Description

The benchmark script (tests/benchmark/benchmark.php) failed to run when user specified a non-exist output csv file via php tests/benchmark/benchmark.php --csv non-exist.csv.

How to reproduce

Dockerfile for reproduce

FROM php:8.4-alpine

# Install dependencies
RUN apk add --no-cache git

# Install composer
COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer

# Clone project
WORKDIR /app
RUN git \
    clone \
    https://github.com/thephpleague/commonmark \
    --branch=2.6.1 \
    --depth=1 \
    /app
RUN composer install

# Run the benchmark
ENTRYPOINT [ "sh", "-c", "php tests/benchmark/benchmark.php --csv benchmark.csv" ]

Current output

$ docker build . -t commonmark && docker run --rm -it commonmark
docker build . -t commonmark && docker run --rm -it commonmark 
[+] Building 1.2s (12/12) FINISHED                                                                                               docker:default
 => [internal] load build definition from Dockerfile                                                                                       0.0s
 => => transferring dockerfile: 471B                                                                                                       0.0s
 => => writing image sha256:931f9a3465f1a4d16eb0913c1ae8904054537d47d4ebaf681adad5c6427d5861                                               0.0s
 => => naming to docker.io/library/commonmark                                                                                              0.0s

Fatal error: Uncaught ValueError: Path must not be empty in /app/tests/benchmark/benchmark.php:123
Stack trace:
#0 /app/tests/benchmark/benchmark.php(123): fopen('', 'w+')
#1 {main}
  thrown in /app/tests/benchmark/benchmark.php on line 123

Expected output

$ docker build . -t commonmark && docker run --rm -it commonmark
Benchmark Results, CPU:
        1) cebe/markdown                1.51 ms              
        2) Parsedown                    1.64 ms      -0.13 ms
        3) cebe/markdown extra          1.80 ms      -0.29 ms
        4) cebe/markdown gfm            1.89 ms      -0.38 ms
        5) PHP Markdown                 2.05 ms      -0.54 ms
        6) PHP Markdown Extra           2.95 ms      -1.44 ms
        7) CommonMark                   5.74 ms      -4.23 ms
        8) CommonMark GFM               5.96 ms      -4.45 ms
        9) CommonMark All Extensions    8.29 ms      -6.78 ms

Possible solution

if ($config['csv'] !== false) {
$stream = ctype_digit($config['csv']) ?
"php://fd/{$config['csv']}" :
realpath($config['csv']);
$fd = @fopen(
$stream,
$config['exec'] === 'exec' ?
'w' : 'w+'
);

Change realpath($config['csv']); to $config['csv'];.

Additional context

No response

Did this project help you today? Did it make you happy in any way?

No response

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