I implementing Mmoreram gearman bundle in my symfony(2.4) project.
I have website that users make action and triggers jobs.
like:
# Get Gearman and tell it to run in the background a 'job'
$id = $this->params['gearman']->doHighBackgroundJob('MYBundleServicesPublishWorker~publish',
json_encode($parameters)
);
And i have one worker that run infinitely and do the jobs (iterations: 0)
I run it from command line once in background:
nohup php /myproject/app/console gearman:worker:execute MYBundleServicesPublishWorker > /tmp/error_log.txt > /tmp/output_log.txt &
The config look like:
gearman:
# Bundles will parsed searching workers
bundles:
# Name of bundle
MyBundle:
# Bundle name
name: myBundle
# Bundle search can be enabled or disabled
active: true
# If any include is defined, Only these namespaces will be parsed
# Otherwise, full Bundle will be parsed
include:
- Services
- EventListener
# Namespaces this Bundle will ignore when parsing
ignore:
- DependencyInjection
- Resources
# default values
# All these values will be used if are not overwritten in Workers or jobs
defaults:
# Default method related with all jobs
# do // deprecated as of pecl/gearman 1.0.0. Use doNormal
# doNormal
# doBackground
# doHigh
# doHighBackground
# doLow
# doLowBackground
method: doNormal
# Default number of executions before job dies.
# If annotations defined, will be overwritten
# If empty, 0 is defined by default
iterations: 0
# execute callbacks after operations using Kernel events
callbacks: true
# Prefix in all jobs
# If empty name will not be modified
# Useful for rename jobs in different environments
job_prefix: null
# Autogenerate unique key in jobs/tasks if not set
# This key is unique given a Job name and a payload serialized
generate_unique_key: true
# Prepend namespace when callableName is built
# By default this variable is set as true
workers_name_prepend_namespace: true
# Server list where workers and clients will connect to
# Each server must contain host and port
# If annotations defined, will be full overwritten
#
# If servers empty, simple localhost server is defined by default
# If port empty, 4730 is defined by efault
servers:
localhost:
host: 127.0.0.1
port: 4730
doctrine_cache:
providers:
gearman_cache:
type: apc
namespace: doctrine_cache.ns.gearman
my problem is when i run app/console cache:clear and after that job come in the worker crash
its throw error :
PHP Warning:
require_once(/myproject/app/cache/dev/jms_diextra/doctrine/EntityManager_53a06fbf221b4.php):
failed to open stream: No such file or directory in
/myproject/app/cache/dev/appDevDebugProjectContainer.php on line 787
PHP Fatal error: require_once(): Failed opening required
'/myproject/app/cache/dev/jms_diextra/doctrine/EntityManager_53a06fbf221b4.php'
(include_path='.:/usr/share/php:/usr/share/pear') in
/myproject/app/cache/dev/appDevDebugProjectContainer.php on line 787
How can i fix it, i try to change the doctrine bundle cache type: file_system/array/apc
but it did not help
How can i overcome this?
what i am doing wrong?
Thanks in advance
i found the problem, i have in my worker this line :
$this->doctrine->resetEntityManager();
that cause this,
now i am only open connection and close it like:
$em = $this->doctrine->getEntityManager();
$em->getConnection()->connect();
# run publish command
............
# close connection
$em->getConnection()->close();
Related
I have a Symfony 5.1.8 project, in which I want to use a different database connection for testing. To do so, I set up the file .env.test.local with a different value for DATABASE_URL than in my .env.local, just like the documentation in the .env file states:
# In all environments, the following files are loaded if they exist,
# the latter taking precedence over the former:
#
# * .env.local contains default values for the environment variables needed by the app
# * .env.local.local uncommitted file with local overrides
# * .env.local.$APP_ENV committed environment-specific defaults
# * .env.local.$APP_ENV.local uncommitted environment-specific overrides
#
# Real environment variables win over .env.local files.
Symfony seems to ignore these overrides and always uses the values provided in .env.local.
To find out what exactly happens I changed the last line in bin/console from $application->run($input); to dd($_ENV); in order to just dump whatever environment variables symfony sees during its execution.
Here are the contents of my different .env files:
.env
APP_ENV=dev
ENV_VAR=ENV
.env.local
APP_ENV=dev
ENV_VAR=ENV_LOCAL
.env.test
APP_ENV=test
ENV_VAR=ENV_TEST
.env.test.local
APP_ENV=test
ENV_VAR=ENV_TEST_LOCAL
When I run php bin/console now the output is as follows:
array:10 [
"APP_ENV" => "dev"
"ENV_VAR" => "ENV_LOCAL"
...
]
Which is what I expect. But when I run php bin/console -e test the following is being printed:
array:10 [
"APP_ENV" => "test"
"ENV_VAR" => "ENV_LOCAL"
...
]
APP_ENV is set correctly, according to the -e parameter, but still, for ENV_VAR the value from .env.local is taken.
Do I have a misconception about the .env-files and their behaviour or is this a bug of some sort?
In case it matters, I am currently working on Windows 10 with PHP 7.3.24.
It was a configuration error on my side.
When I first started this project I did not fully grasp the concept of multi level .env files and did a little change to the bin/console executable, to make things "easier" for me:
curl -o console.temp https://raw.githubusercontent.com/symfony/recipes/master/symfony/console/5.1/bin/console
diff console console.temp
31c31
< (new Dotenv())->bootEnv(dirname(__DIR__) . '/.env.local');
---
> (new Dotenv())->bootEnv(dirname(__DIR__).'/.env');
This, of course prevented the whole DotEnv thingy from working correctly. I just forgot about this change that I introduced, but thanks to #PierrickM's comment on my question, everything is working fine now!
When running drush cim commands in Drupal 8 I get the following error:
Command cim was not found. Drush was unable to query the database. As a result, many commands are unavailable.
Re-run your command with --debug to see relevant log messages.
and when I run the drush cim --debug show the following:
$ drush cim --debug
[preflight] Redispatch to site-local Drush: C:\xampp\htdocs\executive-coatings\docroot/vendor/drush/drush/drush.
[preflight] Config paths: C:/xampp/htdocs/executive-coatings/docroot/vendor/drush/drush/drush.yml
[preflight] Alias paths: C:/xampp/htdocs/executive-coatings/docroot/drush/sites,C:/xampp/htdocs/executive-coatings/drush/sites,C:/xampp/htdocs/executive-coatings/docroot/drush/sites
[preflight] Commandfile search paths: C:\xampp\htdocs\executive-coatings\docroot\vendor\drush\drush\src
[debug] Bootstrap further to find cim [0.27 sec, 6.78 MB]
[debug] Trying to bootstrap as far as we can [0.27 sec, 6.78 MB]
[bootstrap] Drush bootstrap phase: bootstrapDrupalRoot() [0.27 sec, 6.78 MB]
[bootstrap] Change working directory to C:\xampp\htdocs\executive-coatings\docroot [0.27 sec, 6.78 MB]
[bootstrap] Initialized Drupal 8.6.13 root directory at C:\xampp\htdocs\executive-coatings\docroot [0.28 sec, 6.9 MB]
[bootstrap] Drush bootstrap phase: bootstrapDrupalSite() [0.28 sec, 7.15 MB]
[bootstrap] Initialized Drupal site default at sites/default [0.29 sec, 7.37 MB]
[debug] Could not find a Drupal settings.php file at sites/default/settings.php. [0.29 sec, 7.37 MB]
[bootstrap] Drush bootstrap phase: bootstrapDrupalConfiguration() [0.29 sec, 7.37 MB]
[debug] Add service modifier [0.29 sec, 7.51 MB]
[bootstrap] Unable to connect to database. More information may be available by running `drush status`. This may occur when Drush is trying to bootstrap a site that has not been installed or does not have a configured database. In this case you can select another site with a working database setup by specifying the URI to use with the --uri parameter on the command line. See `drush topic docs-aliases` for details. [0.29 sec, 7.51 MB]
[debug] Bootstrap phase bootstrapDrupalDatabase() failed to validate; continuing at bootstrapDrupalConfiguration() [0.29 sec, 7.51 MB]
[debug] Done with bootstrap max in Application::find(): trying to find cim again. [0.29 sec, 7.51 MB]
In Application.php line 239:
[Symfony\Component\Console\Exception\CommandNotFoundException]
Command cim was not found. Drush was unable to query the database. As a result, many commands are unavailable. Re-r
un your command with --debug to see relevant log messages.
Exception trace:
() at C:\xampp\htdocs\executive-coatings\docroot\vendor\drush\drush\src\Application.php:239
Drush\Application->bootstrapAndFind() at C:\xampp\htdocs\executive-coatings\docroot\vendor\drush\drush\src\Application.php:192
Drush\Application->find() at C:\xampp\htdocs\executive-coatings\docroot\vendor\symfony\console\Application.php:236
Symfony\Component\Console\Application->doRun() at C:\xampp\htdocs\executive-coatings\docroot\vendor\symfony\console\Application.php:148
Symfony\Component\Console\Application->run() at C:\xampp\htdocs\executive-coatings\docroot\vendor\drush\drush\src\Runtime\Runtime.php:118
Drush\Runtime\Runtime->doRun() at C:\xampp\htdocs\executive-coatings\docroot\vendor\drush\drush\src\Runtime\Runtime.php:49
Drush\Runtime\Runtime->run() at C:\xampp\htdocs\executive-coatings\docroot\vendor\drush\drush\drush.php:72
require() at C:\xampp\htdocs\executive-coatings\docroot\vendor\drush\drush\drush:4
You probably (like me) are trying to import all the exported configurations from some existing-site (from here on referenced as example.com) into your local (localhost/PROJECT_NAME) for development reasons, but that is currently (middle 2019) not directly supported, and you will have to import the database first, see below for more.
Steps:
Export and download the database from your existing-site (e.g. example.com/admin/config/development/backup_migrate).
In your local, ensure you have enough RAM (maybe close some programs).
Create your local database (DATABASE_NAME) and import previously exported one, using PhpMyAdmin (or something like that, e.g. http://localhost/phpmyadmin/).
Ensure the settings.local.php file exists (in ./sites/default/settings directory), and when it does not exist create it and configure it, for example like:
<?php
$databases['default']['default'] = [
'database' => 'DATABASE_NAME',
'username' => 'root',
'password' => '',
'prefix' => '',
// 'collation' => 'utf8mb4_general_ci',
'host' => '127.0.0.1',
'port' => '3306',
'namespace' => 'Drupal\\Core\\Database\\Driver\\mysql',
'driver' => 'mysql',
];
$settings['drupal_env'] = 'dev';
// Location of the site configuration files:
// (Path used by "drush config-export" command)
# $config_directories['sync'] = '../config/d8_sync';
Ensure the settings.php file exists (in ./sites/default directory), and that it includes above mentioned settings.local.php file (will attach my default settings.php file).
Goto localhost/PROJECT_NAME/core/install.php?rewrite=ok&langcode=en&profile=standard&continue=1 link (just to ensure it shows Drupal is already installed).
Run drush cr (it should now work and clear the cache).
settings.php file:
This is my default settings.php file, which should include settings.local.php (if it exists).
// Salt for one-time login links, cancel links, form tokens, etc:
$settings['hash_salt'] = 'Dxl656Ddme9FyAvn0y02nrnbETVxVnHZwBLilbjSkQLH0-DHqQd2BZL8yPoM0lRCNKRx7_yqVA';
// Deployment identifier:
# $settings['deployment_identifier'] = \Drupal::VERSION;
// Access control for update.php script:
$settings['update_free_access'] = FALSE;
// External access proxy settings:
# $settings['http_client_config']['proxy']['http'] = 'http://proxy_user:proxy_pass#example.com:8080';
# $settings['http_client_config']['proxy']['https'] = 'http://proxy_user:proxy_pass#example.com:8080';
# $settings['http_client_config']['proxy']['no'] = ['127.0.0.1', 'localhost'];
// Reverse Proxy Configuration:
# $settings['reverse_proxy'] = TRUE;
/**
* Specify every reverse proxy IP address in your environment.
* This setting is required if $settings['reverse_proxy'] is TRUE.
*/
# $settings['reverse_proxy_addresses'] = ['a.b.c.d', ...];
// Reverse proxy trusted headers:
# $settings['reverse_proxy_trusted_headers'] = \Symfony\Component\HttpFoundation\Request::HEADER_X_FORWARDED_ALL | \Symfony\Component\HttpFoundation\Request::HEADER_FORWARDED;
// Page caching:
# $settings['omit_vary_cookie'] = TRUE;
// Cache TTL for client error (4xx) responses:
# $settings['cache_ttl_4xx'] = 3600;
// Expiration of cached forms:
# $settings['form_cache_expiration'] = 21600;
// Class Loader:
# $settings['class_loader_auto_detect'] = FALSE;
// Authorized file system operations:
# $settings['allow_authorize_operations'] = FALSE;
/**
* Default mode for directories and files written by Drupal.
*
* Value should be in PHP Octal Notation, with leading zero.
*/
# $settings['file_chmod_directory'] = 0775;
# $settings['file_chmod_file'] = 0664;
// Public file base URL:
# $settings['file_public_base_url'] = 'http://downloads.example.com/files';
// Public file path:
# $settings['file_public_path'] = 'sites/default/files';
// Private file path:
# $settings['file_private_path'] = '';
// Session write interval:
# $settings['session_write_interval'] = 180;
// String overrides:
# $settings['locale_custom_strings_en'][''] = [
# 'forum' => 'Discussion board',
# '#count min' => '#count minutes',
# ];
// A custom theme for the offline page:
# $settings['maintenance_theme'] = 'bartik';
/**
* If you encounter a situation where users post a large amount of text, and
* the result is stripped out upon viewing but can still be edited, Drupal's
* output filter may not have sufficient memory to process it. If you
* experience this issue, you may wish to uncomment the following two lines
* and increase the limits of these variables. For more information, see
* http://php.net/manual/pcre.configuration.php.
*/
# ini_set('pcre.backtrack_limit', 200000);
# ini_set('pcre.recursion_limit', 200000);
// Active configuration settings:
# $settings['bootstrap_config_storage'] = ['Drupal\Core\Config\BootstrapConfigStorageFactory', 'getFileStorage'];
// Configuration overrides:
# $config['system.file']['path']['temporary'] = '/tmp';
# $config['system.site']['name'] = 'My Drupal site';
# $config['system.theme']['default'] = 'stark';
# $config['user.settings']['anonymous'] = 'Visitor';
// Fast 404 pages:
# $config['system.performance']['fast_404']['exclude_paths'] = '/\/(?:styles)|(?:system\/files)\//';
# $config['system.performance']['fast_404']['paths'] = '/\.(?:txt|png|gif|jpe?g|css|js|ico|swf|flv|cgi|bat|pl|dll|exe|asp)$/i';
# $config['system.performance']['fast_404']['html'] = '<!DOCTYPE html><html><head><title>404 Not Found</title></head><body><h1>Not Found</h1><p>The requested URL "#path" was not found on this server.</p></body></html>';
// Load services definition file:
$settings['container_yamls'][] = $app_root . '/' . $site_path . '/services.yml';
// Override the default service container class:
# $settings['container_base_class'] = '\Drupal\Core\DependencyInjection\Container';
// Override the default yaml parser class:
# $settings['yaml_parser_class'] = NULL;
// The default list of directories that will be ignored by Drupal's file API:
$settings['file_scan_ignore_directories'] = [
'node_modules',
'bower_components',
];
// The default number of entities to update in a batch process:
$settings['entity_update_batch_size'] = 50;
// Entity update backup:
$settings['entity_update_backup'] = TRUE;
/**
* Load local development override configuration, if available.
*
* Use settings.local.php to override variables on secondary (staging,
* development, etc) installations of this site. Typically used to disable
* caching, JavaScript/CSS compression, re-routing of outgoing emails, and
* other things that should not happen on development and testing sites.
*
* Keep this code block at the end of this file to take full effect.
*/
if (file_exists($app_root . '/' . $site_path . '/settings.local.php')) {
include $app_root . '/' . $site_path . '/settings.local.php';
}
In my case, I just did not started virtual server (wamp).
Please run this command drush config-import before you run drush cim command.
For more info please refer to this link here
I hope it solves your problem.
When I enable the 'dev' mode in my Symfony 4 app (that is already online in a shared hosting service) it shows this message:
(1/1) ParameterNotFoundException
You have requested a non-existent parameter "locale".
in ParameterBag.php (line 100)
at ParameterBag->get('locale')
in EnvPlaceholderParameterBag.php (line 57)
at EnvPlaceholderParameterBag->get('locale')
in ParameterBag.php (line 216)
at ParameterBag->resolveString('%locale%', array('locale' => true))
in ParameterBag.php (line 187)
...
and does not allow to debug the app. My config/services.yml code is as default:
# Put parameters here that don't need to change on each machine where the app is deployed
# https://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration
parameters:
locale: 'en'
services:
# default configuration for Services in *this* file
_defaults:
autowire: true # Automatically injects dependencies in your Services.
autoconfigure: true # Automatically registers your Services as commands, event subscribers, etc.
public: false # Allows optimizing the container by removing unused Services; this also means
# fetching Services directly from the container via $container->get() won't work.
# The best practice is to be explicit about your dependencies anyway.
...
Please, someone can help me to fix this error.
Had the same problem during the fresh symfony 4.3 + sonata admin bundle installation.
As a solution I added locale parameter:
// /config/services.yaml
parameters:
locale: 'en'
While I am not a Symphony expert the documentation appears to allow anything in the parameters section, but it does mention also defining the values in the .env.dist file as well for them to be used here.
http://symfony.com/doc/current/best_practices/configuration.html#canonical-parameters
When upgrading from symfony 4.2 to symfony 4.4 I also got this error when composer commands.
This parameter seems so be used in config/packages/translation.yml.
Updating the symfony/translation recipe which no longer refers to %locale% but hardcode 'en' solves the problem for me.
Simply run composer recipes:install symfony/translation --force -v
I'm trying to set up sonata block cache but when I setup the http_cache handler I'm getting an exception even when the service seems to be there.
My current test setup is the following
sonata_cache:
caches:
predis:
servers:
- {host: %redis_host%, port: %redis_port%, database: 2}
apc:
token: %secret% # token used to clear the related cache
prefix: %domain% # prefix to ensure there is no clash between instances
# servers:
# - { domain: %domain%, ip: 127.0.0.1, port: 80 }
timeout:
RCV: { sec: 5, usec: 0 }
SND: { sec: 5, usec: 0 }
sonata_block:
http_cache:
# handler: sonata.cache.noop
listener: true
I can see the multiple services that I enabled on the sonata_cache.caches
$ app/console debug:container sonata.cache.noop
[container] Information for service sonata.cache.noop
Service Id sonata.cache.noop
Class Sonata\Cache\Adapter\Cache\NoopCache
Tags
- sonata.cache ()
[...]
If I change the sonata_block setup to:
sonata_block:
http_cache:
handler: sonata.cache.noop
listener: true
I got the following exception
InvalidArgumentException in ContainerBuilder.php line 796 "The service
definition "sonata.cache.noop" does not exist."
Does anyone had a similar issue?
Try to replace :
handler: sonata.cache.noop
to :
handler: sonata.block.cache.handler.noop
I am nearly finished with installing most of the Sonata bundles in Symfony CMF. For now. my final step is finishing with the Sonata PageBundle. I installed all needed dependencies and needed bundles, I changed several config or routing files from app/config using this manual (http://sonata-project.org/bundles/page/master/doc/reference/installation.html).
The problem appears when I want to to do the 'last' step;
php app/console sonata:easy-extends:generate SonataPageBundle
I receive this error:
{ParameterNotFoundException: The service "sonata.page.admin.block" has a dependency on a non-existent parameter "sonata.block.container.types". Did you mean this: "sonata.page.block.container.class"?}
Okay, it is obvious that a dependency parameter is missing, but I am unable to pinpoint the exact problem.
My sonata_page & sonata_block from app/config/config.php;
sonata_page:
multisite: host
use_streamed_response: true # set the value to false in debug mode or if the reverse proxy does not handle streamed response
ignore_route_patterns:
- ^(.*)admin(.*) # ignore admin route, ie route containing 'admin'
- ^_(.*) # ignore symfony routes
ignore_routes:
- sonata_page_cache_esi
- sonata_page_cache_ssi
- sonata_page_js_sync_cache
- sonata_page_js_async_cache
- sonata_cache_esi
- sonata_cache_ssi
- sonata_cache_js_async
- sonata_cache_js_sync
- sonata_cache_apc
ignore_uri_patterns:
- ^/admin\/ # ignore admin route, ie route containing 'admin'
page_defaults:
homepage: {decorate: false} # disable decoration for homepage, key - is a page route
default_template: default # template key from templates section, used as default for pages
templates:
default: { path: 'SonataPageBundle::layout.html.twig', name: 'default' }
2columns: { path: 'SonataPageBundle::2columns_layout.html.twig', name: '2 columns layout' }
# manage the http errors
catch_exceptions:
not_found: [404] # render 404 page with "not_found" key (name generated: _page_internal_error_{key})
fatal: [500] # so you can use the same page for different http errors or specify specific page for each error
sonata_block:
# context_manager: sonata.page.block.context_manager
default_contexts: [cms]
blocks:
sonata.admin.block.admin_list:
contexts: [admin]
#sonata.admin_doctrine_orm.block.audit:
# contexts: [admin]
sonata.block.service.text:
sonata.block.service.rss:
sonata.page.block.container:
sonata.page.block.children_pages:
There is a similar question here on SO, but unanswered for 4 months, Google doesn't have any info (that I was able to find) on this issue.
If someone can point out what is going wrong and where, I would love to hear it..
There is no support for SonataPageBundle by the CMF project yet. So I guess the "symfony-cmf" tag is incorrect?