我有个问题。命令后
composer update
Run Code Online (Sandbox Code Playgroud)
我收到错误消息
[Symfony\Component\Console\Exception\LogicException]
An option named "connection" already exists.
Script Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache handling the symfony-scripts event terminated with an exception
[RuntimeException]
An error occurred when executing the ""cache:clear --no-warmup"" command:
[Symfony\Component\Console\Exception\LogicException]
An option named "connection" already exists.
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
Exception trace:
() at C:\wamp64\www\ecommerce\vendor\symfony\symfony\src\Symfony\Component\Console\Input\InputDefinition.php:232
Symfony\Component\Console\Input\InputDefinition->addOption() at C:\wamp64\www\ecommerce\vendor\symfony\symfony\src\Symfony\Component\Console\Command\Command.php:384
Symfony\Component\Console\Command\Command->addOption() at C:\wamp64\www\ecommerce\vendor\doctrine\doctrine-bundle\Command\Proxy\RunSqlDoctrineCommand.php:24
Doctrine\Bundle\DoctrineBundle\Command\Proxy\RunSqlDoctrineCommand->configure() at C:\wamp64\www\ecommerce\vendor\symfony\symfony\src\Symfony\Component\Console\Command\Command.php:61
Symfony\Component\Console\Command\Command->__construct() at C:\wamp64\www\ecommerce\vendor\doctrine\dbal\lib\Doctrine\DBAL\Tools\Console\Command\RunSqlCommand.php:36
Doctrine\DBAL\Tools\Console\Command\RunSqlCommand->__construct() at C:\wamp64\www\ecommerce\var\cache\dev\appDevDebugProjectContainer.php:11355
appDevDebugProjectContainer->getDoctrine_QuerySqlCommandService() at C:\wamp64\www\ecommerce\vendor\symfony\symfony\src\Symfony\Component\DependencyInjection\Container.php:329
Symfony\Component\DependencyInjection\Container->get() at C:\wamp64\www\ecommerce\vendor\symfony\symfony\src\Symfony\Bundle\FrameworkBundle\Console\Application.php:140
Symfony\Bundle\FrameworkBundle\Console\Application->registerCommands() at C:\wamp64\www\ecommerce\vendor\symfony\symfony\src\Symfony\Bundle\FrameworkBundle\Console\Application.php:100
Symfony\Bundle\FrameworkBundle\Console\Application->all() at C:\wamp64\www\ecommerce\vendor\symfony\symfony\src\Symfony\Bundle\FrameworkBundle\Console\Application.php:64
Symfony\Bundle\FrameworkBundle\Console\Application->doRun() at C:\wamp64\www\ecommerce\vendor\symfony\symfony\src\Symfony\Component\Console\Application.php:122
Symfony\Component\Console\Application->run() at C:\wamp64\www\ecommerce\bin\console:27
Run Code Online (Sandbox Code Playgroud)
我用 git 获取所有项目,并在一台计算机上全部运行,在第二台计算机上不运行。
当我将一个大图像文件夹放入我的 中时/web folder,该"cache"clear"命令失败并显示
“内存不足异常”
PHP Fatal error: Allowed memory size of 536870912 bytes exhausted (tried to allocate 151552 bytes) in /Users/john/Development/git/website/vendor/twig/twig/lib/Twig/Compiler.php on line 124
[Symfony\Component\Debug\Exception\OutOfMemoryException]
Error: Allowed memory size of 536870912 bytes exhausted (tried to allocate 151552 bytes)
Exception trace:
() at /Users/john/Development/git/website/vendor/twig/twig/lib/Twig/Compiler.php:124
Run Code Online (Sandbox Code Playgroud)
图像文件夹包含 10,000 张图像,大小约为 600MB。当我删除此文件夹时,“cache:clear”命令成功运行。
我正在使用Symfony 2.8与PHP 7.1. PHP 内存限制设置为 512MB,这是我的主机上的最大值。
更新:
当我添加--no-warmup到命令时,我没有得到exception.
$ php app/console cache:clear --verbose --no-warmup
Run Code Online (Sandbox Code Playgroud) 我尝试使用Redis设置Symfony 3.1缓存.我按照本教程:
https://symfony.com/blog/new-in-symfony-3-1-cache-component
我安装了predis/predis和SncRedisBundle.
在我的config.yml我已经把
framework:
cache:
app: cache.adapter.redis
default_redis_provider: redis://192.168.34.10
snc_redis:
clients:
default:
type: predis
alias: default
dsn: redis://192.168.34.10
logging: %kernel.debug%
cache:
type: predis
alias: cache
dsn: redis://192.168.34.10
logging: %kernel.debug%
options:
connection_timeout: 10
read_write_timeout: 30
Run Code Online (Sandbox Code Playgroud)
现在,当我尝试通过snc_redis它正常访问redis时.但是当我尝试使用缓存组件时:
public function getLoggedUserAcl($userId)
{
$cachedResources = $this->cacheAdapter->getItem('acl.rules');
$cachedResources->expiresAfter(100);
if ($cachedResources->isHit()) {
dump('hit');
$resources = $cachedResources->get();
} else {
dump('not-hit');
$resources = $this->api->getCollection(Resource::class, null, null, [
'userId' => $userId
]);
$cachedResources->set($resources);
}
return $resources;
}
Run Code Online (Sandbox Code Playgroud)
CacheAdapter是@cache.app服务.
它一直在转储NOT_HIT.在日志中,REDIS没有任何内容.
你能告诉我哪里弄错了或者暗示我可能出错了吗?
在我的 Symfony 5 应用程序中,我想针对不同的任务以及不同的环境使用不同的缓存。
例如我的配置如下所示:
framework:
cache:
pools:
cache.auth:
adapter: cache.adapter.redis
provider: app.my_custom_redis_provider
cache.sap:
adapter: cache.adapter.redis
provider: app.my_custom_redis_provider
services:
app.my_custom_redis_provider:
arguments:
- '%env(REDIS_URL)%'
-
retry_interval: 2
timeout: '%env(REDIS_TIMEOUT)%'
class: Redis
factory:
- Symfony\Component\Cache\Adapter\RedisAdapter
- createConnection
Run Code Online (Sandbox Code Playgroud)
我在我的类中使用依赖注入。那么我如何定义特定类使用这两个缓存池中的哪一个呢?
目前我的缓存是这样的:
class SapListService implements ListServiceInterface
{
use LoggerTrait;
private CountryServiceInterface $countryService;
private CurrencyServiceInterface $currencyService;
public function __construct(
SapClientFactoryInterface $sapClient,
CacheItemPoolInterface $cache,
ParameterBagInterface $params
) {
$sapUser = $params->get('sap_user');
$sapPw = $params->get('sap_pw');
$urlStruktur = $params->get('sap_struktur');
$this->countryService = $sapClient->getCountryService($sapUser, $sapPw, $urlStruktur, $cache);
$this->currencyService = $sapClient->getCurrencyService($sapUser, $sapPw, …Run Code Online (Sandbox Code Playgroud) 我的 symfony 应用程序有多个实例在单独的 docker 容器中运行。
我已经配置我app.cache使用redis:
framework:
cache:
app: cache.adapter.redis
Run Code Online (Sandbox Code Playgroud)
我有同样的prefix_seed:
framework:
cache:
prefix_seed: 'dev'
Run Code Online (Sandbox Code Playgroud)
结果,我在 redis 中遇到了这样的事情:
1605259288.470950 [0 172.18.0.28:55044] "MGET" "HnMEIyUlZ+:workers.restart_requested_timestamp"
1605259288.471680 [0 172.18.0.28:55044] "SET" "HnMEIyUlZ+:workers.restart_requested_timestamp" "d:1605259288.471522;"
1605259314.483389 [0 172.18.0.29:42884] "MGET" "8TMgMtnOAG:workers.restart_requested_timestamp"
Run Code Online (Sandbox Code Playgroud)
从上面可以看出,2 个不同的实例试图通过相同的键从 redis 中获取值,workers.restart_requested_timestamp但即使使用相同的prefix_seed.
在这个例子中,我使用了 messenger 组件,我想通过stop-workers命令(通过共享 redis)停止在任何地方运行的工人。但一般来说这与缓存配置有关。
如何克服这个问题并告诉两个应用程序使用相同的池?这是什么配置?
恐怕我有一个 PHP 初学者问题。我正在使用 Symfony 的缓存组件。https://symfony.com/doc/current/components/cache.html
我在接收 2 个参数($url、$params)的函数内部调用缓存对象。
class MainController extends AbstractController {
public function do($url, $params) {
$cache = new FilesystemAdapter();
return $cache->get('myCacheName', function (ItemInterface $c) {
global $url;
var_dump($url); // ---> null !!!!
}
}
}
Run Code Online (Sandbox Code Playgroud)
我的问题是,我无法访问缓存方法调用内部的函数参数。$url 和 $params 为空。当然,我可以在 MainController 类中使用公共类变量来来回发送变量,但这似乎有点笨拙。
我正在使用symfony并关注使用app_dev.php工作而不用担心缓存的文档...但它对我不起作用.我经常被迫使用clear_cache来查看我在树枝模板中的更改!
我的app_dev.php:
$loader = require_once __DIR__.'/../app/bootstrap.php.cache';
Debug::enable();
require_once __DIR__.'/../app/AppKernel.php';
$kernel = new AppKernel('dev', true);
//$kernel->loadClassCache();
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);
Run Code Online (Sandbox Code Playgroud)
任何帮助,将不胜感激.
[编辑]
config.yml:
imports:
- { resource: parameters.yml }
- { resource: security.yml }
- { resource: services.yml }
framework:
#esi: ~
translator: { fallbacks: [%locale%] }
secret: "%secret%"
router:
resource: "%kernel.root_dir%/config/routing.yml"
strict_requirements: ~
form: ~
csrf_protection: ~
validation: { enable_annotations: true }
templating:
engines: ['twig']
#assets_version: SomeVersionScheme
default_locale: "%locale%"
trusted_hosts: ~ …Run Code Online (Sandbox Code Playgroud)