new environment with debug mode off still detects kernel.debug as true - php

I have the following new environment:
<?php
use Symfony\Component\ClassLoader\ApcClassLoader;
use Symfony\Component\HttpFoundation\Request;
$loader = require_once __DIR__.'/../app/bootstrap.php.cache';
// Use APC for autoloading to improve performance
// Change 'sf2' by the prefix you want in order to prevent key conflict with another application
/*
$loader = new ApcClassLoader('sf2', $loader);
$loader->register(true);
*/
require_once __DIR__.'/../app/AppKernel.php';
//require_once __DIR__.'/../app/AppCache.php';
$kernel = new AppKernel('mobile', false);
$kernel->loadClassCache();
//$kernel = new AppCache($kernel);
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);
however when I do the following:
sudo php app/console assetic:dump --env=mobile
it gives me:
Clearing the cache for the mobile environment with debug true
How is it possible that debug is set to true while I have specifically in the new AppKernel('mobile' false);
I have cleared the cache and everything but it is still the same
When I do the following:
$kernel = $this->get('kernel');
ladybug_dump($kernel->isDebug());
this returns false, however it's just the console command that is not getting it right

sudo php app/console assetic:dump --env=dev --no-debug

Related

bootstrap.php.cache in a Symfony 3.4 application

I am looking to confirm how my app*.php files should be configured with regards to the bootstrap.php.cache file.
I have read some conflicting advice on how to treat this file in Symfony 3.0 and above, namely
https://symfonycasts.com/screencast/symfony3-upgrade/new-dir-structure#moving-bootstrap-php-cache and https://gist.github.com/mickaelandrieu/5d27a2ffafcbdd64912f549aaf2a6df9#files-to-move-update-
My understanding is that bootstrap.php.cache is required for a performance boost and is only required or recommended in the 'prod' environment. So this leaves me with the following setup:
app.php:
/** #var \Composer\Autoload\ClassLoader $loader */
$loader = require __DIR__.'/../vendor/autoload.php';
include_once __DIR__.'/../var/bootstrap.php.cache';
$kernel = new AppKernel('prod', false);
app_dev.php:
/** #var \Composer\Autoload\ClassLoader $loader */
$loader = require __DIR__.'/../vendor/autoload.php';
Debug::enable();
$kernel = new AppKernel('dev', true);
Previously $loader was /app/autoload.php, which has been moved to /vendor and /app/bootstrap.php.cache has been deleted and the DistrubutionBundle is now writing that file to /var.
Is this setup correct? (bin/console --env=dev/prod returns no errors)

Symfony2 annotation routing causes cache:clear to fail

I'm having a bunch of problems with routing in Symfony2 and I'm at my wits end searching for an answer.
I'm currently trying to use the #Route annotation. In the dev environment with debug enabled, everything works. In prod with debug enabled, everything works. If I disabled debug, only the index route responds, everything else returns a 404.
I initially thought it was the cache, so I followed the usual process of clearing it. That led to my next problem:
[Doctrine\Common\Annotations\AnnotationException]
[Semantical Error] The annotation "#Sensio\Bundle\FrameworkExtraBundle\Configuration\Route" in method LeagueOfData\Controller\DefaultController::indexAction() does not exist, or could not be auto-loaded.
This error appears when you run bin/console cache:clear --env=prod or bin/console cache:clear --env=dev.
So I checked everything was set up correctly (bare in mind, this works completely fine in the browser with debug enabled no matter the environment).
routing.yml
parser:
resource: "#LeagueOfData/Controller/"
type: annotation
This is included in config.yml and routing_dev.yml (due to the dev override).
AppKernal.php
public function registerBundles()
{
$bundles = [
new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
new Symfony\Bundle\MonologBundle\MonologBundle(),
new Symfony\Bundle\TwigBundle\TwigBundle(),
new Symfony\Bundle\SecurityBundle\SecurityBundle(),
new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
new LeagueOfData\LeagueOfData()
];
if (in_array($this->getEnvironment(), ['dev', 'test'], true)) {
$bundles[] = new Symfony\Bundle\DebugBundle\DebugBundle();
$bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
}
return $bundles;
}
SensioFrameworkExtraBundle is registered correctly. (Full source: https://github.com/Acaeris/lol-parser/blob/broken-routing/app/AppKernel.php)
app.php
<?php
use Symfony\Component\HttpFoundation\Request;
/** #var \Composer\Autoload\ClassLoader $loader */
$loader = require __DIR__ . '/../app/autoload.php';
include_once __DIR__ . '/../app/bootstrap.php.cache';
$kernel = new AppKernel('prod', false);
$kernel->loadClassCache();
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);
app_dev.php
<?php
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Debug\Debug;
/** #var \Composer\Autoload\ClassLoader $loader */
$loader = require __DIR__.'/../app/autoload.php';
Debug::enable();
$kernel = new AppKernel('dev', true);
$kernel->loadClassCache();
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);
As you can see, not much difference. The key seems to be in enabling debug... but why?
Full source is on GitHub if it'll help anyone: https://github.com/Acaeris/lol-parser/tree/broken-routing
You need to import it with an use statement, as example:
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
Hope this help

How to disable Symfony3 caching for dev environment?

I cannot disable Symfony3 cache for my project, can you please help me?
Things that I already tried to do:
commenting the line $kernel->loadClassCache(); in web/app_dev.php
adding
twig:
cache: false
to config_dev.yml
My $kernel instantiation in app_dev.php: $kernel = new AppKernel('dev', true);

composer install pass command line argument or parameter to bin/console

I'm trying to make my symfony 3.0 app capable to work with multiple kernel.
real aim : Multiple applications in one project
Generally everything is OK. I edited bin/console it's content exactly as the following. It works exactly and results what I need via php bin/console --app=api
But when I execute composer install bin/console throws the Exception naturally it doesn't knows about --app parameter. I want to make something like composer install --app=api and desired behaviour it would pass the parameter to bin/console I checked documentation and almost every pixel of the internet couldn't find a solution.
#!/usr/bin/env php
<?php
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Debug\Debug;
// if you don't want to setup permissions the proper way, just uncomment the following PHP line
// read http://symfony.com/doc/current/book/installation.html#configuration-and-setup for more information
//umask(0000);
set_time_limit(0);
/**
* #var Composer\Autoload\ClassLoader $loader
*/
$loader = require __DIR__.'/../apps/autoload.php';
$input = new ArgvInput();
$env = $input->getParameterOption(array('--env', '-e'), getenv('SYMFONY_ENV') ?: 'dev');
$app = $input->getParameterOption(array('--app', '-a'));
$debug = getenv('SYMFONY_DEBUG') !== '0' && !$input->hasParameterOption(array('--no-debug', '')) && $env !== 'prod';
if ($debug) {
Debug::enable();
}
switch ($app) {
case 'api':
$kernel = new ApiKernel($env, $debug);
break;
case 'frontend':
$kernel = new FrontendKernel($env, $debug);
break;
default:
throw new \InvalidArgumentException("[--app|-a=<app>] app: api|frontend");
break;
}
$application = new Application($kernel);
$application->getDefinition()->addOptions([
new InputOption('--app', '-a', InputOption::VALUE_REQUIRED, 'The application to operate in.'),
]);
$application->run($input);
You can use composer install --no-scripts to prevent automatically running app/console after installation.
Or you can remove the the bin/console commands from the scripts section in your composer.json altogether, which probably makes more sense. See https://github.com/symfony/symfony-standard/blob/master/composer.json#L33-L34
Or you can use environment variables instead of arguments.

Symfony2.3 production page blank 500

after working with my project on dev mod, i found some problems with prod on OVH.
it shows me a blank page ! i try to follow the issue on app.php and i found that the problem persist with the execution of $response = $kernel->handle($request); and it don't logging on prod.
so when i change the row on app.php : $kernel = new AppKernel('prod', false); with $kernel = new AppKernel('dev', false); it works well !!!
here's my app.php
<?php
/*
* This file is part of the Sonata package.
*
* (c) Thomas Rabaix <thomas.rabaix#sonata-project.org>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
umask(0000);
require_once __DIR__ . '/../app/bootstrap.php.cache';
require_once __DIR__ . '/../app/AppKernel.php';
//use Symfony\Component\HttpFoundation\Request;
// if you want to use the SonataPageBundle with multisite
// using different relative paths, you must change the request
// object to use the SiteRequest
use Sonata\PageBundle\Request\SiteRequest as Request;
$request = Request::createFromGlobals();
$kernel = new AppKernel('prod', false);
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);
EDIT :
in dev and prod local mode test it works well with
php app/console cache:clear --env=prod --no-debug
php app/console assets:install web_directory
php app/console assetic:dump web_directory
should i add or install php5 on my project ?
EDIT :
my project contains : sonata-project, fosUserBundle,etc...
EDIT
the problem was on config_prod.xml
doctrine:
orm:
entity_managers:
default:
metadata_cache_driver: apc
query_cache_driver: apc
result_cache_driver: apc
intil now after it return an error 500 ! why ? because of apc was not enabled !
so my question how to enable apc on OVH pro !
Go to web/config.php and comment ot the following lines:
if (!in_array(#$_SERVER['REMOTE_ADDR'], array(
'127.0.0.1',
'::1',
))) {
header('HTTP/1.0 403 Forbidden');
exit('This script is only accessible from localhost.');
}
That will enable the config.php to be called from "extern". Don't forget to remove the comments after you've checked everything.
If you have console access on the production server, enter the root directory of your project and call php app/check.php to run the checks on the console.

Categories