0

I am trying to debug some code on my Drupal 9 application.

For example, at the file web/index.php, I try to add die('Was here')

<?php 

    use Drupal\Core\DrupalKernel;
    use Symfony\Component\HttpFoundation\Request;

    $autoloader = require_once 'autoload.php';

    //My code is here
    die('Was here');

    $kernel = new DrupalKernel('prod', $autoloader);

    $request = Request::createFromGlobals();
    $response = $kernel->handle($request);
    $response->send();
    $kernel->terminate($request, $response);

At first, I got the result on my browser. Next I delete this die function, and when i refresh my browser, I get the same as before as if I didn't change the code

After some minutes, the expected result is shown in my browser. So weird

So I am wondering why is Drupal isn't taking that code change into account.

Btw, I run the command drush cr but it didn't change anything

beta-developper
  • 1,689
  • 1
  • 13
  • 24
  • Maybe your site is also cached on some other level? BTW, isn't it only "drush cr", not "drush -cr"? – MilanG Dec 25 '20 at 07:07
  • I actually don't know, this is why I posted here. About the command I mistyped it. it's like you said `drush cr` – beta-developper Dec 25 '20 at 11:34
  • @beta-developper , I have tested new installed Drupal 9.1 in my WAMP env and it works without any issue. You may check the following 1. drupal cache setting 2. web server cache config 3. your browser cookie about cache. Have you tried the debugging with incognito (chrome) or private mode(FF) which ignore cookie and cache? – John Jan 05 '21 at 03:37
  • Does it makes any difference if you are logged in or not? – MilanG Jan 05 '21 at 09:16
  • @John I am gonna deep check that – beta-developper Jan 05 '21 at 11:11
  • @MilanG Actually it doesn't make a difference – beta-developper Jan 05 '21 at 11:12
  • Is any kind of file sync involved here (usually when using docker, vm's etc)? – Jim Panse Jan 05 '21 at 14:39
  • 1
    You might be hitting opcache. Have you tried restarting your php-fpm service after the modification? If this makes your modification work everytime, check your php.ini setup (or additional .ini files loaded for php). In development, I always set `opcache.enable=0` to avoid this. In production, you better keep opcache enabled, of course, for better performance. – Héctor Paúl Cervera-García Jan 05 '21 at 21:06
  • @HéctorPaúlCervera-García exactly it was opcache who caused this behavior. Disabling it solved the problem. – beta-developper Jan 06 '21 at 11:36
  • @JimPanse No there was no sync involved. The problem was caused by OpCache who was enabled. – beta-developper Jan 06 '21 at 11:37

1 Answers1

1

That sounds like PHP OpCode Cache. You can see if its enabled or not in the Drupal status report under "PHP OPcode caching". There's a page on on disabling Drupal Caching [here][1] which includes a section on opcache. I believe to disable opcache you can add an entry to your php.ini file.

opcache.enable=0

Be sure to restart relevant services like php-fpm. And verify it was effective in the Drupal status report. [1]: https://www.drupal.org/node/2598914

dabonde
  • 359
  • 1
  • 11