functions-framework-php icon indicating copy to clipboard operation
functions-framework-php copied to clipboard

Running locally in a container when mounting volumes, I'm not getting a hot reload

Open rmoskal opened this issue 5 years ago • 4 comments

Should I be?

rmoskal avatar Jan 24 '20 23:01 rmoskal

It's not an official feature but it sure would be useful, and I see no reason why it wouldn't work if set up properly. Can you share your docker run command and the contents of your Dockerfile?

bshaffer avatar Jan 27 '20 15:01 bshaffer

No worries. I'm using docker and docker-compose. I'm just using your docker file:

FROM gcr.io/gae-runtimes/php73:php73_20191020_7_3_10_RC00


WORKDIR /srv

# NOTE: The entrypoint "/start", which starts up NGINX and PHP-FPM,
# is configured by creating a `.googleconfig/app_start.json` file with the
# contents:
#
#     {"entrypointContents": "CUSTOM_ENTRYPOINT"}
#
# We configure it to use the `router.php` file included in this package.
RUN mkdir .googleconfig && \
    echo '{"entrypointContents": "serve vendor/bin/router.php"}' > .googleconfig/app_start.json

# Copy over composer files and run "composer install"
COPY composer.* ./
COPY --from=composer:1 /usr/bin/composer /usr/local/bin
RUN composer install --no-dev

# Copy over all application files
COPY . .

# Set a runtime name (required by the base image)
ENV GAE_RUNTIME php73

With a vanilla docker-compose file, that I start with docker-compose up.

version: "3.0"
services:
  php:
    build: .
    restart: on-failure
    ports:
      - 8080:8080
    env_file:
      - .env
    volumes:
      - ./app:/srv/app
    networks:
      - townz_db
networks:
  townz_db:
    external:
      name: agt_master_townz-database

I'm using the http call to kick off a batch php script. My problem was that I was heavily editing the batch script and the changes would not be picked up by the http function unless I restarted the container.

This was wrecking havoc with my development flow.

However, I eventually realized that I didn't need to use the http function to debug at all. I can just bash into the container and run the php script from the command line.

Still, would be a nice feature!

rmoskal avatar Jan 27 '20 15:01 rmoskal

After looking into it, the issue is that OPCache is enabled (makes sense in production! Not so much for hot reloading in development).

You can disable it easily by adding an *.ini file in the root of your application which disables opcache:

; php.ini
opcache.enable = Off

... or by turning opcache off in development inside index.php or anywhere else:

// just turn it off
ini_set('opcache.enable', 'Off');

bshaffer avatar Jan 27 '20 21:01 bshaffer

It would be great to have some sort of DEBUG environment variable, but I'd want this to be standard across all functions frameworks.

Node uses the environment variable NODE_ENV, which is set to production (see here).

bshaffer avatar Feb 21 '20 19:02 bshaffer

We're going to close this for now while we find a standard way to do this across all functions frameworks.

josephlewis42 avatar Apr 21 '23 20:04 josephlewis42