Closed bmilagre closed 1 year ago
Have you defined the environment in a CRAFT_ENVIRONMENT
environment variable as per the .env
example?
# The environment Craft is currently running in (dev, staging, production, etc.)
CRAFT_ENVIRONMENT=dev
https://github.com/craftcms/craft/blob/97f9cfed7301381873046ca3a0b7919bce7ad75e/.env.example.dev#L8
Yes its defined and accessible inside craft.
Can you please try catching the context panic errors as per https://github.com/putyourlightson/craft-blitz/commit/49624dd1a43a8be197a30441df441e2664b1be22, to see if we can get any more helpful info?
Our environment is not set with the same name as described in the doc, but is later correctly defined as CRAFT_ENVIRONMENT.
.env
# The environment Craft is currently running in (dev, staging, production, etc.)
ENVIRONMENT=production
web/index.php
// Load and run Craft
define('CRAFT_ENVIRONMENT', getenv('ENVIRONMENT') ?: 'production');
I dumped it before the try & catch and it seems to exist.
bmilagre@wk-web:/var/www/html$ ./craft blitz/cache/generate
Generating Blitz cache...
[> ] 0% (0/141) ETA: n/a
CRAFT_ENVIRONMENT: production
Errors from the context panic
[2023-02-27 11:23:49] Uncaught Error in child process or thread with message "Undefined constant "CRAFT_ENVIRONMENT"" and code "0"; use Amp\Parallel\Sync\ContextPanicError::getOriginalTrace() for the stack trace in the child process or thread
[2023-02-27 11:23:49] #0 /var/www/html/vendor/amphp/parallel/lib/Sync/ExitFailure.php(39): Amp\Parallel\Sync\ExitFailure->createException()
[2023-02-27 11:23:49] #0 /var/www/html/vendor/craftcms/cms/src/services/Config.php(289): include()
[2023-02-27 11:23:49] Blitz cache generation complete.
Console requests don't go through web/index.php
and it looks like you may be running an old version of index.php
:
https://github.com/craftcms/craft/blob/main/web/index.php
The environment is now set as part of the bootstrapping process: https://github.com/craftcms/cms/blob/aad45b7d4c7005a0ac4809f32e135c6eadec7062/bootstrap/bootstrap.php#L92-L93
I suggest you update to use CRAFT_ENVIRONMENT
, which should also resolve this issue.
It looked like the upgrade to v4 was not done cleanly by us. I copied the following files based on the new version in my project:
bootstrap.php
craft
web/index.php
What solved the problem for me though was upgrading phpdotenv from 3.4
to 5.4
Thanks for your support!
Ah yes, that catches lots of people out, documented here for reference: https://craftcms.com/docs/4.x/upgrade.html#entry-script
The catching of context panic errors has been released in version 4.4.0.
Description After installing Blitz Cache I wanted to generate the cache via Command. However, when executing the command it aborts already at the beginning with the error message "Undefined constant "CRAFT_ENVIRONMENT"" and code "0".
The named variable exists and is callable within Craft. So its probably something wrong set up.
console.log
Blitz version 4.3.3
Craft CMS version 4.3.9
PHP version 8.0.26