Magento php file is cached in google cloud, how to disable caching?

Keywords: Magento - Google Cloud Platform - How to - Other

Description:
I have created a simple helloworld file in Magento Bitnami 2.4.2. (see below), running in the google cloud.

It works fine but when i increment the counter in the echo instruction, google will allways use the old file for 24 hours.
I don’t now where it is cached and how to disable this one. It’s not the browser cache (i’ve used different ones)

I’ve tried a header function to disable this cache, no results.

Has anyone an idea? thank you.

my simple php:

<?php declare(strict_types=1); namespace RW\phptest\Controller\Index; use Magento\Framework\App\Action\Action; class Index extends Action { public function execute() { header("Cache-Control: no-store, must-revalidate"); echo "Hello PHPTest 1 "; } } ?>

Hi @remy,

The following guide shows how you can disable the cache for Magento:

https://docs.bitnami.com/installer/apps/magento/administration/use-cache/#disable-the-cache

Can you try if it works?

Regards,
Michiel

Hi michiel and thanks for the answer.

but no, it doesn’t help:

I’ve deleted my last magento VM and installed today a complete new VM in Google Cloud (bitnami-magento-2-4-2-32-r70).
then i have only created a php helloworld File (… registration.php, module.xml, routes.xml, controller)

-> if i call my helloworld file, it prints a white page and at the top: “Hello PHPTest 1” (for example) -> that’s fine.

But when i then only change the counter from 1 to 2 (with vi) and recall the file, there is no change: it prints allways “Hello PHPTest 1” (and not …2)
Yet i don’t now if it will do the same thing tomorrow with this new VM, but i suppose that it will call the new file in 24 hours.

Then i have only disabled all the cache (“System-> Tools-> Cache Management”) and now i have this error if i call the helloworld:

# Error 503 Backend fetch failed
Backend fetch failed
### Guru Meditation:
XID: 230085
Varnish cache server

and i can’t neither call the backend nor log in my VM now, i think i have to reinstall again the complete VM …

I suppose it has to do with the Varnish cache but also with permissions:
for creating the helloworld file i had to run: “sudo bin/magento-cli setup:upgrade” after creating the module.xml file. During this execution it prints:

Running data recurring...Reading /bitnami/magento/composer.json
Loading config file /bitnami/magento/composer.json
Checked CA file /etc/ssl/certs/ca-certificates.crt: valid
<warning>Cannot create cache directory /usr/sbin/.composer/cache/repo/https---repo.magento.com/, or directory is not writable. Proceeding without cache</warning>
<warning>Cannot create cache directory /usr/sbin/.composer/cache/repo/https---repo.packagist.org/, or directory is not writable. Proceeding without cache</warning>
<warning>Cannot create cache directory /usr/sbin/.composer/cache/files/, or directory is not writable. Proceeding without cache</warning>
Failed to initialize global composer: Composer could not find the config file: /usr/sbin/.composer/composer.json
To initialize a project, please create a composer.json file as described in the https://getcomposer.org/ "Getting Started" section
Reading /bitnami/magento/vendor/composer/installed.json
Reading /bitnami/magento/composer.lock
Checking for "magento/composer-root-update-plugin: 1.1.0" for the Web Setup Wizard...
Reading /bitnami/magento/var/vendor/magento/composer-root-update-plugin/composer.json
Loading config file /bitnami/magento/var/vendor/magento/composer-root-update-plugin/composer.json
<warning>Cannot create cache directory /usr/sbin/.composer/cache/repo/https---repo.packagist.org/, or directory is not writable. Proceeding without cache</warning>
No Web Setup Wizard update needed for magento/composer-root-update-plugin; version 1.1.0 is already in /bitnami/magento/var.

perhaps you know what happens?

kind regards

Rémy

Hi @remy,

I just followed the steps you mentioned and created a new helloworld.php file inside the pub directory of Magento

$ cat /opt/bitnami/magento/pub/helloworld.php
<?php echo 'Hello World 1'; ?>

I accessed the localhost/helloworld.php file and obtained the “Hello World 1” string. However, when I edited it and accessed the file again, I continued obtaining the same string

bitnami@bitnami-magento-6586:/opt/bitnami/magento$ sudo sed -i 's/1/2/g' /opt/bitnami/magento/pub/helloworld.php
bitnami@bitnami-magento-6586:/opt/bitnami/magento$ cat /opt/bitnami/magento/pub/helloworld.php
<?php echo 'Hello World 2'; ?>
bitnami@bitnami-magento-6586:/opt/bitnami/magento$ curl -L localhost/helloworld.php
Hello World 1

So I started to investigate this:

  • First of all, I purged the Varnish cache
curl -X PURGE -H 'X-Magento-Tags-Pattern: .*' localhost/helloworld.php

https://magento.stackexchange.com/questions/303382/purge-specific-link-from-magento-2-varnish

but nothing changed

bitnami@bitnami-magento-6586:/opt/bitnami/magento$ curl -L localhost/helloworld.php
Hello World 1

So I disabled opcache in PHP. I edited the /opt/bitnami/php/etc/php.ini file and disabled opcache

[opcache]
; Determines if Zend OPCache is enabled
opcache.enable = 0

and restarted the services for the change to take effect

sudo /opt/bitnami/ctlscript.sh restart php-fpm
sudo /opt/bitnami/ctlscript.sh restart apache

and requested the file again. This time the response was the expected one

bitnami@bitnami-magento-6586:/opt/bitnami/magento$ curl -L localhost/helloworld.php
Hello World 2

I also edited the file again and confirmed that the output is updated instantly

bitnami@bitnami-magento-6586:/opt/bitnami/magento$ sudo sed -i 's/2/3/g' /opt/bitnami/magento/pub/helloworld.php
bitnami@bitnami-magento-6586:/opt/bitnami/magento$ curl -L localhost/helloworld.php
Hello World 3

Can you check this and let me know if that works for you?

Happy to help!


Was my answer helpful? Click on :heart:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.