php-cli (v1.13.0): $argv[0] is "frankenphp" and the script path is shifted to $argv[1] — breaks Symfony Console
Maintainer thường phản hồi trong vòng 1 ngày
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 30/100
Hướng nghiên cứu
Start by reading caddy/php-cli.go and trace how its argument vector reaches frankenphp_execute_script_cli and do_php_cli. Compare the resulting $argv and $argc with native PHP and FrankenPHP 1.12.7 using the reproduction in the issue. Done means php-cli exposes the script path as $argv[0] and the remaining arguments in the same positions as native PHP.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
What happened?
Since v1.13.0, frankenphp php-cli script.php args... exposes the binary name as $argv[0] and shifts the script path to $argv[1] ($argc grows by one). Native php and FrankenPHP ≤ 1.12.7 expose the script path as $argv[0], as documented for the CLI SAPI.
Minimal reproduction (same PHP 8.5.11, only FrankenPHP differs):
<?php printf("PHP %s SAPI=%s argc=%d argv=%s\n", PHP_VERSION, PHP_SAPI, $argc, json_encode($argv));
# dunglas/frankenphp:1.12.7-php8.5
php /t/argv.php foo bar → PHP 8.5.11 SAPI=cli argc=3 argv=["/t/argv.php","foo","bar"]
frankenphp php-cli /t/argv.php foo bar → PHP 8.5.11 SAPI=cli argc=3 argv=["/t/argv.php","foo","bar"]
# dunglas/frankenphp:1.13.0-php8.5
php /t/argv.php foo bar → PHP 8.5.11 SAPI=cli argc=3 argv=["/t/argv.php","foo","bar"]
frankenphp php-cli /t/argv.php foo bar → PHP 8.5.11 SAPI=cli argc=4 argv=["frankenphp","/t/argv.php","foo","bar"]
$_SERVER['argv'] shows the same shift. SCRIPT_NAME, PHP_SELF and SCRIPT_FILENAME are correct in both versions. Passing -- does not help (-- then shows up inside $argv).
Impact: anything that treats $argv[0] as the script and $argv[1] as the first argument breaks. The most visible case is Symfony Console: ArgvInput drops argv[0] and takes the next element as the command name, so every command fails with
Command "/app/bin/console" is not defined.
This affects frankenphp php-cli bin/console doctrine:migrations:migrate, messenger:consume, messenger:stop-workers, etc. The HTTP server and worker mode are unaffected.
Likely cause: #1757 ("simply use the built-in php-cli"). caddy/php-cli.go now builds the argument vector as append([]string{os.Args[0]}, os.Args[2:]...) (the binary name is prepended so option parsing works like php -i) and passes it unchanged through frankenphp_execute_script_cli to do_php_cli(argc, argv). The real php binary shifts the vector after option parsing so that the script becomes $argv[0]; that shift does not happen on this code path, so user scripts see the raw vector including the binary name. The pre-1.13 emulation built the vector starting at the script path, which is why it was correct before.
Expected: frankenphp php-cli script.php a b gives $argv === ["script.php","a","b"], exactly like php script.php a b.
Build Type
Official Docker image (dunglas/frankenphp:1.13.0-php8.5); also reproduced with a custom build of v1.13.0.
Worker Mode
No — CLI only (php-cli), unrelated to worker mode.
Operating System
GNU/Linux (Debian-based official image; host: Linux x86_64, podman 5.8)
CPU Architecture
x86_64
PHP configuration
phpinfo() output
PHP 8.5.11 (bundled in the official image), default php.ini, no custom extensions needed to reproduce. The repro script above has no dependencies.
Relevant log output
Relevant log output
$ podman run --rm -v $PWD/argv.php:/t/argv.php:ro dunglas/frankenphp:1.13.0-php8.5 frankenphp version
FrankenPHP v1.13.0 PHP 8.5.11 Caddy v2.11.7 h1:yj0Y4fYZGPkSvibBJ1sTWE33xC0fxztVyXEW5iIdUT4=
$ podman run --rm -v $PWD/argv.php:/t/argv.php:ro dunglas/frankenphp:1.13.0-php8.5 frankenphp php-cli /t/argv.php foo bar
PHP 8.5.11 SAPI=cli argc=4 argv=["frankenphp","\/t\/argv.php","foo","bar"]
$ podman run --rm -v $PWD/argv.php:/t/argv.php:ro dunglas/frankenphp:1.12.7-php8.5 frankenphp php-cli /t/argv.php foo bar
PHP 8.5.11 SAPI=cli argc=3 argv=["\/t\/argv.php","foo","bar"]
# Symfony 7.4 app, same container, v1.13.0:
$ frankenphp php-cli /app/bin/console doctrine:migrations:migrate -n
Command "/app/bin/console" is not defined.
- Ngôn ngữ chính
- Go
- Star
- 11.4k
- Fork
- 487
- Merge trung bình
- 2 ngày 19 giờ
- Pull request đã merge (30 ngày)
- 20
Chuẩn bị môi trường
- Có Dockerfile hoặc tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của php/frankenphp
-
Segfault of the whole process when restarting an unhealthy thread: SG(server_context) is read after ts_free_thread()Có thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
php/frankenphp#2688 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 90/100
php/frankenphp#2671 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Include frankenphp version in logsCó thể đã có người làm @ousamabenyounes đã nhận 78 ngày trước. Đang mởenhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
php/frankenphp#2483 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
suggestion about compile.mdCó thể làm lại được Pull request cho issue này đã bị đóng mà không được merge. Đang mởenhancement
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 68/100
php/frankenphp#601 · 5 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
php/frankenphp#2695 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của php/frankenphp
Issue tương tự
-
automation models
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Bug pulumi/pulumi
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
stripe/stripe-cli#2130 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Linux notifications: the default action's ' ' label shows as a blank button in xfce4-notifydĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
kovidgoyal/kitty#10625 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 6 ngày