The crux of the issue is that I edit a code file and the change does not take effect until after I rebuild my entire environment. Weird thing is that I haven't been having this issue for months of development so far. I just decided to dust off this project and work on it this week and all of a sudden editing files no longer works (without a rebuild).
I don't even know where to begin to try and tackle this. Any advise helps, especially from people who have experience with Lando and Docker. Alright, so because I don't have any idea what's causing this, I'll just try and explain my whole set up and go from there:
I'm using Lando to run a container which is running PHP 7.3. When I SSH into the running container and execute my script php worker.php
my script runs no problems. Then if I edit it, say to add a var_dump('hello world!'), I get the expected output. However, if I edit an autoloaded class file, say MyClass.php, and add a var_dump there, nothing happens. In fact I have to completely rebuild the environment with lando rebuild
in order to get the var_dump to show up. Weird right?
Ok so here are some things I've tried:
lando destroy
and lando rebuild
to start fresh.cat mylib/MyClass.php
and I see the added var_dump statement!! However when I run php worker.php
the var_dump added to MyClass isn't there. How can it be present in the filesystem, yet absent during execution? This is really throwing me for a loop.include_once
. This works perfectly, edits take effect as soon as they happen. The problem is that I don't want to manually include all my files, I want to use the composer autoloader. I've been using it for a long time, I'd prefer to just fix whatever has suddenly gone wrong with it.Ok lastly, some theories of mine:
So some things I know people might ask for: Dockerfile
FROM php:7.3-apache
RUN apt-get update \
&& apt-get install -y \
git \
zip \
unzip \
libzip-dev \
libxml2-dev \
libssl-dev \
libc-client-dev \
libkrb5-dev \
&& docker-php-ext-configure imap --with-kerberos --with-imap-ssl \
&& CFLAGS="-I/usr/src/php" docker-php-ext-install zip mysqli pdo pdo_mysql xmlreader imap
RUN curl --silent --show-error https://getcomposer.org/installer | php
RUN mv composer.phar /usr/local/bin/composer
# Bake composer dependencies into the image for production
WORKDIR /app
COPY composer.json ./
COPY composer.lock ./
RUN export COMPOSER_ALLOW_SUPERUSER=1 && \
composer install --no-scripts --no-autoloader --no-dev
COPY . ./
RUN export COMPOSER_ALLOW_SUPERUSER=1 && \
composer dump-autoload --optimize && \
composer run-script post-install-cmd
COPY vhost.conf /etc/apache2/sites-available/000-default.conf
RUN chown -R www-data:www-data ./ && \
a2enmod rewrite
EXPOSE 80
.lando.yml
name: mysite
env_file:
- .env
proxy:
appserver:
- mysite.lndo.site
database:
- db.mysite.lndo.site
services:
appserver:
type: compose
services:
build: .
command: apache2-foreground
database:
type: mysql
portforward: 3306
creds:
---super secret---
composer.json
{
"name": "MySite/MySite",
"description": "Would work great if not for caching issues. :(",
"type": "project",
"require": {
"ext-json": "*",
"ext-imap": "*",
"doctrine/orm": "^2.6.2",
"doctrine/migrations": "^2.0",
"zbateson/mail-mime-parser": "^1.1",
"rct567/dom-query": "^0.7.0",
"sabre/xml": "^2.1",
"phpmailer/phpmailer": "^6.0"
},
"autoload": {
"psr-4": {
"MySite\\": "./lib"
}
}
}
Update:
I've found that by deleting vendor/symfony/console
and then running composer install
it seems to clear the cache. I wish I could figure it out from here, but the answer still eludes me. What does symfony console have to do with autoload caching code?? I have no idea.
I finally figured it out, but it took me all day. I hope someone stumbles across this and it saves you time. Here is what I had to do, it was so easy:
Just put the following code into your composer.json file and run composer install
!
"config": {
"optimize-autoloader": true
},
I don't know WHY this works though. I kind of would assume that enabling the optimizer would CAUSE caching, but instead it seems to disable it. I honestly have no idea why this works. If someone else can explain this better than me, then I'd vote for your answer over mine.