Giter VIP home page Giter VIP logo

Comments (5)

dunglas avatar dunglas commented on September 12, 2024 1

Can you show the PHP code that triggers this error please?

from frankenphp.

withinboredom avatar withinboredom commented on September 12, 2024 1

Here's an example script:

<?php

while(frankenphp_handle_request(function() {
    $value = $_ENV['stuff'] ?? null;
    echo "_ENV: $value\n";

    $value = getenv('stuff');
    echo "getenv: $value\n";

    $value = $_SERVER['stuff'] ?? null;
    echo "_SERVER: $value\n";
})) {}

And the output:

// sudo stuff="abcs" ./frankenphp php-server --worker worker.php,2

> curl -k http://localhost/worker.php
_ENV:
getenv: abcs
_SERVER: abcs

Note: if I set php.ini's variable_order to EGPCS, then it is always filled:

❯ curl -k http://localhost/worker.php
_ENV: abcs
getenv: abcs
_SERVER: abcs

I can't reproduce your issue.

from frankenphp.

mateusfmello avatar mateusfmello commented on September 12, 2024 1

I added variables_order = EGPCS to 10-app.ini and it apparently solved the problem, now that is a bit strange considering that this configuration is the PHP default, so in theory it should already be working, according to the documentation.

I'll leave this noted so I can check it next week with a standard project. If I can reproduce the problem, I'll upload the project here on Github along with the PR to add the line variables_order = EGPCS.

from frankenphp.

mateusfmello avatar mateusfmello commented on September 12, 2024

This is a method to generate the correct API URL, where in the production environment it adds HTTPS and in development it adds HTTP.

public static function getURLAPI(Request $request): string {

		$schemaURL = 'http' . (strtolower($_ENV['APP_ENV']) === 'prod' ? 's' : '') . '://';
		$url       = $schemaURL . $request->getHost();

		if ($request->getPort() != 80 && $request->getPort() != 443)
			$url .= ':' . $request->getPort();

		return $url . $request->getPathInfo();
	}

You can access this link and you will see that in proximaPagina each time the page is updated it will be with HTTPS and the next with HTTP, when it is with HTTP it gives the error in the log:

{"level":"info","ts":1723499344.042241,"msg":"[error] Warning: Undefined array key \"APP_ENV\"","syslog_level":"notice"}

Running cat .env.local.php gives this result:

<?php

// This file was generated by running "composer dump-env prod"

return array (
  'APP_ENV' => 'prod',
  'SYMFONY_DOTENV_PATH' => './.env',
  'SOURCE_COMMIT' => 'XXXXX',
  'COOLIFY_FQDN' => 'XXXXX',
  'COOLIFY_URL' => 'XXXXX',
  'COOLIFY_BRANCH' => 'XXXXX',
  'COOLIFY_CONTAINER_NAME' => 'XXXXX',
  'APP_SECRET' => 'XXXXX',
  'CORS_ALLOW_ORIGIN' => '^https://(www.)?XXXXX.com.br$',
  'DATABASE_URL' => 'XXXXX',
  'JWT_PASSPHRASE' => 'XXXXX',
  'JWT_PUBLIC_KEY' => 'XXXXX',
  'JWT_SECRET_KEY' => 'XXXXX',
  'JWT_TEMPO_VIDA' => 'XXXXX',
  'QNT_PUBLICACOES_POR_PAGINA' => '20',
  'SERVER_NAME' => 'api.aposentadoriadoinss.com.br:80',
  'STORAGE_BUCKET' => 'XXXXX',
  'STORAGE_ENDERECO' => 'XXXXX',
  'STORAGE_ENDERECO_IMAGENS' => 'XXXXX/imagens',
  'STORAGE_KEY' => 'XXXXX',
  'STORAGE_REGIAO' => 'XXXXX',
  'STORAGE_SECRET' => 'XXXXX',
  'TINY_PNG_KEY' => 'XXXXX',
  'PORT' => '80',
  'HOST' => '0.0.0.0',
);

Running echo $APP_ENV gives this result:

prod

These commands were run inside the resulting container from Dockerfile

from frankenphp.

withinboredom avatar withinboredom commented on September 12, 2024

Does the error still happen when you use getenv() or $_SERVER instead of $_ENV?

Note: getenv isn't thread safe, so if you have things changing the environment during runtime (like a dotenv module), you could end up with a segfault.

from frankenphp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.