FPM vs CLI - getcwd() !== $_SERVER['DOCUMENT_ROOT'] and include_path
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- C
- Star
- 40.4k
- Fork
- 8.1k
- Merge trung bình
- 2 ngày 13 giờ
- Pull request đã merge (30 ngày)
- 96
Mô tả
Description
I'm not yet sure whether this is a bug or an improvement in documentation suffices.
$_SERVER['DOCUMENT_ROOT'] is set by the FPM SAPI (therefore also in INPUT_SERVER 'DOCUMENT_ROOT') and should generally be equal to nginx's root ($document_root) path
However, there is also getcwd() which, unless set in www.conf chdir and modified in https://github.com/php/php-src/blame/master/sapi/fpm/fpm/fpm_unix.c#L457 which should be identical to DOCUMENT_ROOT.
However it is not.
e.g.
root /foo/bar
request: /hello/world.php
which is located in /foo/bar/hello/world.php
DOCUMENT_ROOT will be /foo/bar
but getcwd() will be /foo/bar/hello (essentially dirname( $_SERVER['SCRIPT_FILENAME'] ) )
I'm unable to find where this change of directory happens though - since it's not in https://github.com/php/php-src/blame/master/sapi/fpm/fpm/fpm_unix.c#L457 and there are no other chdir happening.
Could anyone pinpoint this?
php-fpm 5.2 (?) seemed to have
https://linux.die.net/man/8/php-fpm
-C
Do not chdir to the script's directory
which was removed though (I couldn't find details on why though)
This generally is not an issue, however it might be extremely unexpected when using exec() for example.
Would it not make more sense if by default the fpm SAPI would use the DOCUMENT_ROOT by default as cwd?
Where it becomes confusing though is:
https://www.php.net/manual/en/ini.core.php#ini.include-path
Using a . in the include path allows for relative includes as it means the current directory.
"current directory" means DIR and not getcwd() ?
Except in CLI:
https://www.php.net/manual/en/features.commandline.differences.php
The CLI SAPI does not change the current directory to the directory of the executed script.
where it means getcwd() and not DIR ?
Would it make sense to somehow standardize eventually?
Sorry, if this reads confusing, but so am I atm
PHP Version
8.4
Operating System
No response
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.
Hướng nghiên cứu
Bắt đầu với sapi/fpm/fpm/fpm_unix.c quanh dòng được tham chiếu và thiết lập chdir trong www.conf, sau đó so sánh hành vi của FPM và CLI được mô tả trong tài liệu được liên kết. Hoàn tất nghĩa là xác định nơi thư mục làm việc thay đổi và xác định xem hành vi hoặc tài liệu về include-path có cần được làm rõ hay không.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- nginx, php
- Lĩnh vực
- backend
- Loại issue
- Lỗi
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Cần làm rõ
- Mức phù hợp với người mới
- 28/100