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
Related
I would like deploy my Symfony 4 website thanks to AWS Lambda and Symfony Bref, I followed this docs :
https://bref.sh/docs/frameworks/symfony.html
https://www.vertcitron.fr/node-lambda-serverless/
but I have this error :
My serverless.yaml file :
service: bref-symfony
package:
exclude:
- node_modules/**
- venv/**
provider:
name: aws
region: eu-west-3
runtime: provided
environment:
# Symfony environment variables
APP_ENV: prod
plugins:
- ./vendor/bref/bref
functions:
website:
handler: public/index.php
timeout: 30 # in seconds (API Gateway has a timeout of 30 seconds)
layers:
- ${bref:layer.php-73-fpm}
events:
- http: 'ANY /'
- http: 'ANY /{proxy+}'
console:
handler: bin/console
timeout: 120 # in seconds
layers:
- ${bref:layer.php-73} # PHP
- ${bref:layer.console} # The "console" layer
What is the problem please ?
It looks like you need to cut back on what is included in your app image. Make sure you are running prod-only dependencies on composer:
composer inst --no-dev -o
You also can add something like this to your serverless.yaml to only include the files you need to run your Symfony app:
package:
exclude:
- '*'
- '**'
include:
- 'bin/**'
- 'config/**'
- 'public/index.php'
- 'src/**'
- 'var/cache/prod/**'
- 'translations/**'
- 'vendor/**'
- '.env'
I have problem with Symfony 4 integration with GeniusesOfSymfony/WebSocketBundle, routing file for pubsub is not loading.
Installed everything
'gos/web-socket-bundle dev-master '
'gos/pubsub-router-bundle v0.3.2'
Created file _/config/packages/gos_web_socket.yaml_ with content
gos_web_socket:
server:
port: 1337 #The port the socket server will listen on
host: 127.0.0.1 #The host ip to bind to
router:
resources:
- '%kernel.project_dir%/config/pubsub.yaml'
topics:
- "#app.topic.chat"
And file '/config/pubsub.yaml' with content
app_topic_chat:
channel: 'app/chat/{first_user}/{second_user}'
handler:
callback: 'chat.topic' #related to the getName() of your topic
requirements:
first_user:
pattern: '\d+' #accept all valid regex, don't put delimiters !
second_user:
pattern: '\d+'
Getting always error
!! In DelegatingLoader.php line 37:
!!
!! Cannot load resource "/var/www/html/cms/config/pubsub.yaml".
Please help
Eh, problem was in naming.
It was
'%kernel.project_dir%/config/pubsub.yaml'
but need to be
'%kernel.project_dir%/config/pubsub.yml'
so yml not yaml
I have configured logger for different channel in different files, but it does not work for me. It's work but it writes in console not in pointed file.
And I need write log to file in channel search.
Here is my code:
#app/config/config_dev.yml
monolog:
handlers:
search:
type: stream
level: error
path: "%kernel.logs_dir%/search_log.log"
channels: [search]
main:
type: stream
path: "%kernel.logs_dir%/%kernel.environment%.log"
level: debug
channels: [!event, !search]
console:
type: console
channels: [!event, !doctrine, !search]
Defined service:
#MyBundle/Resources/config/services.yml
services:
app.logger_search:
class: Symfony\Bridge\Monolog\Logger
arguments: ["#logger"]
tags:
- {name: monolog.logger, channel: search}
Now use it service, try to test it:
#MyController.php
/**
* #Route("/test")
*/
public function test()
{
$this->get("app.logger_search")->error("Test");
return $this->json("test");
}
But it writes into console insted of file.
Console I meant where I ran my server: php bin\console server:run.
Creating your own Channel. This is done either via the configuration or by tagging your service with monolog.logger and specifying which channel the service should log to (just as you have done).
Both ways are valid and in both cases you logger will be named:
monolog.logger.<you-channel-name>
So use monolog.logger.search instead of your service id app.logger_search to fix the issue.
I you don't have a strong reason to change the logger behavior, I suggest to configure additional channels without tagged services:
# app/config/config.yml
monolog:
channels: ['foo', 'bar']
With this, you can now send log messages to the foo channel by using the automatically registered logger service monolog.logger.foo.
I'm trying to use the S3 Cache Resolver of LiipImagineBundle to upload my cached thumbnails to S3 but I'm exepriencing some strange issues.
I'm using the AWS SDK v ^3.2:
"aws/aws-sdk-php": "^3.2",
I'm using Symfony2 and in my services.yml, I've configured the Aws\Credentials\Credentials class and the Aws\S3\S3Client that uses it to create the client:
shq.amazon.s3Credentials:
class: Aws\Credentials\Credentials
arguments: ["%amazon.s3.key%", "%amazon.s3.secret%"]
shq.amazon.s3:
class: Aws\S3\S3Client
arguments:
- version: %amazon.s3.version%
region: %amazon.s3.region%
credentials: "#shq.amazon.s3Credentials"
All works well, and I'm able to upload files to S3.
Now, the configuration of LiipImagineBundle: it seems that LiipImagineBundle has configuration rules that apply only to AWS SDK 2 and that causes "false positives" using the aws_s3 cache resolver.
I've tried at least three different configurations.
CONFIGURATION 1: FOR AWS SDK 2
liip_imagine:
resolvers:
default:
web_path: ~
cache_s3:
aws_s3:
client_config:
key: %amazon.s3.key%
secret: %amazon.s3.secret%
region: %amazon.s3.region%
version: %amazon.s3.version%
bucket: %amazon.s3.bucket%
get_options:
Scheme: 'https'
put_options:
CacheControl: 'max-age=86400'
cache: cache_s3
filter_sets:
thumb_purchase:
filters:
thumbnail: { size: [250, 250], mode: outbound }
interlace:
mode: line
This throws an exception:
An exception has been thrown during the rendering of a template
("Error retrieving credentials from the instance profile metadata
server. (cURL error 28: Connection timed out after 1006 milliseconds
(see http://curl.haxx.se/libcurl/c/libcurl-errors.html))") in
src/AppBundle/Resources/views/Store/show.html.twig at line 135.
This is thrown by the AWS SDK that is searching for credentials and doesn't find them.
So, this approach seems not working.
CONFIGURATION 2: USING Aws\Credentials (AWS SDK 3)
The way to pass credentials to S3Client is passing an instance of Aws\Credentials. I do this through a service so I can reuse the same credentials in other services (and that works as I use it to upload files to S3!):
shq.amazon.s3Credentials:
class: Aws\Credentials\Credentials
arguments: ["%amazon.s3.key%", "%amazon.s3.secret%"]
and in config.yml the :
liip_imagine:
resolvers:
cache_thumb_purchase:
aws_s3:
client_config:
version: %amazon.s3.version%
region: %amazon.s3.region%
credentials: "#shq.amazon.s3Credentials"
bucket: %amazon.s3.bucket%
get_options:
Scheme: 'https'
put_options:
CacheControl: 'max-age=86400'
filter_sets:
thumb_purchase:
cache: cache_thumb_purchase
filters:
thumbnail: { size: [250, 250], mode: outbound } # Transforms 50x40 to 32x26, no cropping
interlace:
# mode can be one of none,line,plane,partition
mode: line
As you can see, I pass the Credentials service to LiipImagineBundle but I get this error FROM Aws\ClientResolver:
InvalidArgumentException in ClientResolver.php line 296:
Invalid configuration value provided for "credentials". Expected Aws\Credentials\CredentialsInterface|array|bool|callable, but got string '#shq.amazon.s3Credentials' (length=25)
credentials: (Aws\Credentials\CredentialsInterface|array|bool|callable)
Specifies the credentials used to sign requests. Provide an
Aws\Credentials\CredentialsInterface object, an associative array of "key",
"secret", and an optional "token" key, false to use null credentials, or
a callable credentials provider used to create credentials or return null.
See Aws\Credentials\CredentialProvider for a list of built-in credentials
providers. If no credentials are provided, the SDK will attempt to load
them from the environment.
It seems that, instead of passing the class Credentials referenced by #shq.amazon.s3Credentials, it passes simply the string #shq.amazon.s3Credentials, so the ClientResolver, correctly, reports that the passed parameter is incorrect.
So, this configuration doesn't work, too.
CONFIGURATION 3: PASSING AN ARRAY TO S3Client (AWS SDK 3)
The third way of instantiating a S3Client is passing an associative array to hardcode credentials.
So I tried this configuration:
liip_imagine:
resolvers:
cache_thumb_purchase:
aws_s3:
client_config:
version: %amazon.s3.version%
region: %amazon.s3.region%
#credentials: "#shq.amazon.s3Credentials"
credentials:
key: %amazon.s3.key%
secret: %amazon.s3.secret%
...
But this time I receive an error from LiipImagineBundle, that seems doesn't accept an array as parameter:
InvalidTypeException in ScalarNode.php line 36: Invalid type for path
"liip_imagine.resolvers.cache_thumb_purchase.aws_s3.client_config.HERE_THERE_IS_DIRECTLY_MY_AWS_KEY".
Expected scalar, but got array.
I think that the configuration rules of the bundle have to be updated but i don't know how to do this as I'm not yet so confident with such kind of things.
So, how can I make LiipImagineBundle / Symfony to pass the class instead of the string that refers to the Credentialsclass? Is a fault of mine, or is something broken in LiipImagineBundle?
(Also, strange thing that I don't understand, instead of using the term "key" in the path, it use the value of "key" that is HERE_THERE_IS_DIRECTLY_MY_AWS_KEY.
So it reports a path like this liip_imagine.resolvers.cache_thumb_purchase.aws_s3.client_config.HERE_THERE_IS_DIRECTLY_MY_AWS_KEYinstead of a path like liip_imagine.resolvers.cache_thumb_purchase.aws_s3.client_config.key - that to me seems more correct, doesn't it?).
Have you tried this?
liip_imagine:
resolvers:
cache_thumb_purchase:
aws_s3:
client_config:
credentials:
key: %amazon.s3.key%
secret: %amazon.s3.secret%
version: %amazon.s3.version%
region: %amazon.s3.region%
bucket: %amazon.s3.bucket%
get_options:
Scheme: 'https'
put_options:
CacheControl: 'max-age=86400'
filter_sets:
thumb_purchase:
cache: cache_thumb_purchase
filters:
thumbnail: { size: [250, 250], mode: outbound } # Transforms 50x40 to 32x26, no cropping
interlace:
# mode can be one of none,line,plane,partition
mode: line
services:
admin.amazon.s3:
class: Aws\S3\S3Client
factory_class: Aws\S3\S3Client
factory_method: 'factory'
arguments:
- key: %amazon.s3.key%
secret: %amazon.s3.secret%
region: %amazon.s3.region%
version: %amazon.s3.version%
I'm starting to work on this LiipImagineBundle + KnpGaufretteBundle + "aws/aws-sdk-php": "^3.18" right now
I am working in Windows and trying to deplay my project in prod on Debian server. I am using svn. I changed my config.yml to handle the path of node and less.
When I try to do :php app/console assetic:dump --env=prod on the server I receive an Error : PHP Catchable fatal error: Argument 2 passed to Assetic\Filter\LessFilter::__construct() must be of the type array, string given, called in /var/www/ales/app/cache/prod/appProdProjectContainer.php on line 549 and defined in /var/www/ales/vendor/kriswallsmith/assetic/src/Assetic/Filter/LessFilter.php on line 54
Herewith my configuration :
assetic:
debug: "%kernel.debug%"
use_controller: false
bundles: ['MyAppliCoreBundle']
java: /usr/bin/java
filters:
cssrewrite: ~
cssembed:
jar: %kernel.root_dir%/resources/java/cssembed-0.4.5.jar
less:
node: /usr/lib/nodejs
node_paths: [/usr/lib/node_modules]
apply_to: "\.less$"
cssrewrite: ~
yui_css:
jar: "%kernel.root_dir%/ressources/java/yuicompressor-2.4.8.jar"
assets:
bootstrap_css:
inputs:
- %kernel.root_dir%/../vendor/twbs/bootstrap/less/bootstrap.less
filters:
- less
- cssrewrite
jquery:
inputs:
- %kernel.root_dir%/../vendor/jquery/jquery/jquery-2.1.1.js
output: js/jquery.js
When I try on DEV I get this error :
22:45:00 [file+] /var/www/ales/app/../web/assetic/bootstrap_css.less
[Assetic\Exception\FilterException]
An error occurred while running:
'/usr/lib/nodejs' '/tmp/assetic_lessBjeLzE'
Error Output:
sh: 1: /usr/lib/nodejs: Permission denied
Input:
// Core variables and mixins
#import "variables.less";
#import "mixins.less";
I checked permission and set to 777 /usr/lib/nodejs but nothing change.
If you need more details, don't hesitate.
Symfony2 with bootstrap 3 on debian.
which node return :
/usr/local/bin/node
wich nodejs return :
/usr/bin/nodejs
and echo $NODE_PATH return :
/usr/lib/nodejs:/usr/lib/node_modules:/usr/share/javascript
Thanks a lot for your help, I was planning to set in prod this weekend...
I had the same problem and solved it well, first you can try with this configuration:
less:
node: "node"
node_paths:
- "/usr/lib/node_modules"
- "%kernel.root_dir%/../../../node_modules"
if later you have this Error: Cannot find module 'less' you have to install the module:
npm install -g less
I hope I have been helpful!!