php / php/php-src

php_admin_[flag|value] falsely applies config changes

Ouverte
#10,117 1 commentaire 0 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

Bug SAPI: fpm Status: Needs Triage
Langage dominant
C
Étoiles
40.4k
Forks
8.2k
Merge moyen
2 j 13 h
PR mergées (30 j)
96

Description

Description
Quick explanation of the problem.

When using strace I noticed stat system calls for the files already in opcache, even though opcache.enable_file_override is set to 1. The system calls are triggered by is_file() being invoked from PHP.

php_admin_flag[opcache.enable_file_override] = On is set in the pool config /etc/php/8.1/fpm/pool.d/www.conf

var_dump(opcache_get_configuration()) when being invoked through an fpm process says:

["opcache.enable_file_override"]=>
  | bool(true)

phpinfo() says the same, enable_file_override is On.

I suspect the actual value of the flag is Off.

How to reproduce the issue.
  1. Ensure that opcache is enabled and enable_file_override is disabled (disabled by default). Also, set in the ini file:
opcache.file_update_protection=0
opcache.validate_permission=0
opcache.validate_timestamps=0
  1. Apply the fpm pool settings for simplicity of testing:
pm = static
pm.max_children = 1
  1. Add three test scripts to the document root of apache server:
    test_opcache.php
<?php

echo "test begin\n";

$file1 = 'include_1.php';
$file2 = 'include_2.php';

if (is_file($file1)) {
    include $file1;
}

if (is_file($file2)) {
    include $file2;
}

echo "test end\n";

plus two more scripts in the same directory:
include_1.php

<?php

echo __FILE__ . "\n";

include_2.php

<?php

echo __FILE__ . "\n";
  1. Invoke the test_opcache.php to warm up the opcache via curl request or browser.
  2. Attach to the child fpm process using strace -p <pid> -e newfstatat,fstat,stat.
  3. Invoke the test_opcache.php again. Expected strace output:
newfstatat(AT_FDCWD, "/", {st_mode=S_IFDIR|0755, st_size=4096, ...}, 0) = 0
newfstatat(AT_FDCWD, "include_1.php", {st_mode=S_IFREG|0644, st_size=29, ...}, 0) = 0
newfstatat(AT_FDCWD, "include_2.php", {st_mode=S_IFREG|0644, st_size=29, ...}, 0) = 0
  1. Set php_admin_flag[opcache.enable_file_override] = On in the pool config and restart apache and fpm.
  2. Check if the config value is changed via var_dump(opcache_get_configuration()).
  3. Repeat steps 4, 5, and 6. The strace output won't change.
  4. Set opcache.enable_file_override=1 in the php.ini file and repeat steps 4, 5, and 6. The output will change to
newfstatat(AT_FDCWD, "/", {st_mode=S_IFDIR|0755, st_size=4096, ...}, 0) = 0
Conclusion

The opcache.enable_file_override flag works only when it's set in the ini file.
The worst thing is that setting the flag in the pool config gives a false positive result in opcache_get_configuration() and phpinfo(), which might be very misleading.

PHP Version

PHP 8.1.13

Operating System

Ubuntu 18.04

Guide de contribution

Ouvrir le guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Piste de recherche

Commencez par retracer la manière dont php_admin_flag[opcache.enable_file_override] de /etc/php/8.1/fpm/pool.d/www.conf est appliqué, en le comparant à opcache.enable_file_override dans php.ini. Utilisez opcache_get_configuration(), phpinfo() et la reproduction avec strace pour vérifier que la valeur rapportée et le comportement de file-stat concordent lorsque le paramètre du pool est activé.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
c
Domaine
backend, performance
Type d'issue
Bug
Difficulté
4/5
Temps estimé
3-5 jours
Activité
À l'abandon
Clarté
Plutôt claire
Accessibilité débutants
45/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.