php / php/php-src

FPM vs CLI - getcwd() !== $_SERVER['DOCUMENT_ROOT'] and include_path

Abierto
#19,584 3 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Feature SAPI: fpm
Lenguaje dominante
C
Estrellas
40.4k
Forks
8.2k
Merge medio
2 d 13 h
PR fusionados (30 d)
96

Descripción

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

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Comienza con sapi/fpm/fpm/fpm_unix.c alrededor de la línea indicada y la configuración chdir de www.conf; después, compara el comportamiento de FPM y CLI descrito en la documentación enlazada. Se considera terminado cuando se haya identificado dónde cambia el directorio de trabajo y se haya determinado si es necesario aclarar el comportamiento o la documentación de la ruta de inclusión.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
nginx, php
Área
backend
Tipo de issue
Error
Dificultad
4/5
Tiempo estimado
3-5 días
Estado de actividad
Estancado
Claridad
Necesita aclaración
Aptitud para principiantes
28/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.