I recently discovered that my profiler is not working. Every time I try to open the profiler from /app_dev.php/_profiler/empty/search/results?ip=&limit=10 I get this empty profiler page:
With default and customc onfiguration. Here the custom one:
framework:
profiler:
dsn: 'file:/tmp/symfony-profiler'
And here a more precise configuration:
framework:
profiler:
dsn: "file:%kernel.root_dir%/../var/cache/%kernel.environment%/profiler"
No calls are stored in theprofiler. No log keep trace of what happens under the carpet.
Symfony needs the same file permissions to write the profiling data as it would for logs or the cache. Does Symfony write the files if the DSN is left at the default which would write them into var/cache/dev/profiler (or app/var with an older version).
It's also possible that the profiler service has been overridden, which can be checked with bin/console debug:container profiler and other such tools.
Related
I try to install Symfony CMF with SonataDoctrinePHPCRAdminBundle() and CmfTreeBrowserBundle().
According to docs there's an option in app/config.yml to prevent administrative routes be view-able in admin interface:
# app/config/config.yml
cmf_routing:
# ...
dynamic:
# ...
persistence:
phpcr:
# ...
use_sonata_admin: false
But I receive an error both in the console and on the site:
"Unrecognized option "use_sonata_admin" under
"cmf_routing.dynamic.persistence.phpcr"
What could it be?
we are in the process of moving to cmf version 2. the tutorial is currently outdated. sonata admin is now all configured at the new admin bundle, not on cmf_routing anymore. if you want something that works as documented, please use the 1.3 release and the 1.3 documentation. if you are trying out new things, see github.com/symfony-cmf/symfony-cmf-docs/milestone/4 for what documentation can be expect to work or not yet. any help in updating the doc is appreciated of course ;-)
I have a site built on Symfony framework and I had to add a legacy php script launched directly in the web directory.
I also have to share session's data between the Symfony framework controllers and the stand-alone php script.
Sessions on my server and the Symfony framework are configured to be in a memcached server (127.0.0.1 11211).
Here are my Symfony config files :
parameters.yml
session_memcached_host: 127.0.0.1
session_memcached_port: 11211
session_memcached_prefix: 'BPY_'
session_memcached_expire: 3600
config.yml
imports:
- { resource: session.yml }
...
session:
handler_id: session.handler.memcached
session.yml
services:
session.memcached:
class: Memcache
arguments:
persistent_id: %session_memcached_prefix%
calls:
- [ addServer, [ %session_memcached_host%, %session_memcached_port% ]]
session.handler.memcached:
class: Symfony\Component\HttpFoundation\Session\Storage\Handler\MemcacheSessionHandler
arguments: [#session.memcached, { prefix: %session_memcached_prefix%, expiretime: %session_memcached_expire% }]
Session in the Symfony controllers are set and read using :
$request->getSession->get('key');
$request->getSession->set('key', $value);
In the stand-alone old php script, I use the global session array to set and get data. And in theory, to allow Symfony and my script share data I set and get data in :
$_SESSION['_sf2_attributes']
So, finally with this configuration, when I set data in the symfony controllers I do not see it in the stand-alone php script and when I set data in the php script I do not see it in the Symfony controllers.
What is wrong in my configuration or my code?
You should check the Bridge a legacy Application with Symfony Sessions
but overall you can configure it in the following way:
framework:
session:
storage_id: session.storage.php_bridge
handler_id: ~
I finally solved the problem.
In the parameters.yml file I put :
session_memcached_prefix : ''
instead of :
session_memcached_prefix : 'BPY_'
and the two envirennements can share sessions data.
In the Symfony controllers I still use
$request->getSession->get('key');
$request->getSession->set('key', $value);
And in the stand-alone php script I use set and get data in this array :
$_SESSION['_sf2_attributes']
So
$_SESSION['_sf2_attributes']['key'] = $value
I am moving my Symfony 2 project to production environment on shared hosting. When I execute the file app.php I get error of
Fatal error: Call to undefined function Doctrine\Common\Cache\apc_fetch() in /data/web/virtuals/53627/virtual/www/vendor/doctrine/cache/lib/Doctrine/Common/Cache/ApcCache.php on line 40
I contacted the hosting provider and was told that they no longer user APC caching, which seems to be outdated, so they moved further.
Is there any way how to omit APC caching using Symfony + Doctrine?
Thank you
Check out your app/config.yml: the Doctrine cache drivers are pretty configurable, and as the doc states, you could just set them to array. That would look pretty much like this:
doctrine:
orm:
auto_mapping: true
metadata_cache_driver: array
query_cache_driver: array
result_cache_driver: array
Also note that this is basically the default configuration, so the defaults must've been overridden.
How to disable profiler in Symfony2 in production?
I do not mean the toolbar - I mean the profiler.
I want to disable it in production, I use it extensively for development so the solution with removing its bundle is a no-go.
I have tried setting framework.profiler.only_exceptions to true. I have tried removing the framework.profiler section altogether. No matter what the profiler.db is growing after every request and every response contains x-debug-token header.
I have double-checked the config files (config.yml and config_prod.yml) and everything seems to be fined.
What's more the command app/console router:dump-apache --no-debug always dumps the _wdt and _profiler routes, but I don't have them in my routing_prod.yml and they don't seem to be present when trying to access them from the browser (404).
I'm running symfony 2.0 and I won't upgrade right now because of some major changes in 2.1 which would require a rewrite of many elements. It wouldn't be wise to start it just before initial deployment.
Symfony >= 2.2
As of Symfony 2.2 the profiler supports an enabled flag in the framework's configuration and is disabled by default in the test environment.
# app/config/config_test.yml
framework:
profiler:
enabled: false
See this Blog entry about Profiling by Fabien Potencier and the FrameworkBundle configuration reference for more details.
Update: This flag is still valid in Symfony 4.0.
Symfony <= 2.1
In Symfony <= 2.1 The profiler is disabled entirely if there's no framework.profilerkey in the configuration.
You can see this in the ProfilerPass of the Symfony2 FrameworkBundle configuration.
This is the case for the default config.yml and config_prod.yml (which includes the former). So if you didn't tinker with the default configurations you're fine.
In config_dev.yml however the default setting is:
framework:
profiler: { only_exceptions: false }
Which enables profiling for the dev environment and all enviroments that import config_dev.yml like config_test.yml.
If you want to unset the profiler value in a subsequent configuration use:
framework:
profiler: false
Values like {} or ~ won't unset the value. You have to use false.
Did you try this (enable only for development)
As the profiler adds some overhead, you might want to enable it only
under certain circumstances in the production environment. The
only-exceptions settings limits profiling to 500 pages, but what if
you want to get information when the client IP comes from a specific
address, or for a limited portion of the website? You can use a
request matcher:
framework:
profiler:
matcher: { ip: 192.168.0.0/24 }
http://symfony.com/doc/current/book/internals.html#profiler
or
the profiler can be disabled on a per-action basis by doing something like:
if(in_array($this->container->get('kernel')->getEnvironment(), array('prod'))) {
$this->container->get('profiler')->disable();
}
I figured it out, but still I'm not sure why the profiler settings didn't work. I did clear the cache with --no-debug after each change of the configuration.
Firstly I examined the Configuration of FrameworkBundle and found out that profiler conf node has canBeDisabled(). Then I checked what does it mean exactly.
It turns out that each canBeDisabled node has an implied child node enabled with default value set to true. You can either override it or set the parent node directly to false or null to disable the section. If you simply omit the profiler section then it is enabled by default.
Maybe I missed it in the docs, but I'm pretty sure it should be mentioned here. Also, in my opinion profiler should be disabled by default in production. I can't imagine a scenario when it would be beneficial to run profiler in production in the long run. I'll be happy if anybody proves me wrong.
BTW I noticed then as the profiler.db grows then each request becomes slower, but that may not be the case in prod.
I'm new to Symfony and I'm going through the Jobeet tutorial v1.4 for
Doctrine. I am currently stuck on Day 3. I've followed all the
instructions on configuring the database and building models and
modules; however, when I try to access
"http://localhost:8080/frontend_dev.php" I receive the following
error:
'Configuration "config/databases.yml" does not exist or is unreadable.'
My config/databases.yml file looks like this:
all:
doctrine:
class: sfDoctrineDatabase
param:
dsn: 'mysql:host=localhost;dbname=jobeet'
username: root
password: mysecret
Creating the tables and loading the fixtures seem to work fine after checking the database with phpmyadmin. Any help would be appreciated.
Thank you!
I tried what's in the Jobeet from Day 1 to 3 and it works on my local machine, maybe what you have there is some file permission issue that is preventing your symfony to load the config/databases.yml so please change permissions as needed (chmod in linux).
Not sure if this will solve the problem but I think this is worth to try, execute php symfony cc or simply clear the cache folder and load up again your app in the browser, since the config/databases.yml is to be cached as config_databases.yml.php (you can take a look on /cache/frontend/dev/config/)
phpmyadmin? arrggggghhhhhhh =P
Anyway, your identation is wrong.
It should be like this:
all:
doctrine:
class: sfDoctrineDatabase
param:
dsn: "mysql:host=localhost;dbname=jobeet"
username: root
password: mysecret
As for the error, if you're on a mac, change the permissions using chmod. :-)
If you're stuck on a problem with databases.yml, this symfony databases.yml configuration reference could be useful: www.symfonyreference.com/databases-yml