Symfony 2.8清除缓存并超时

时间:2016-11-30 14:10:08

标签: php mysql symfony

清除缓存时出现此错误: SQLSTATE[HY000] [2002] Operation timed out

我在docker-compose上使用symfony 2.8(db,php,phpmyadmin,nginx) 我没有任何问题将我的php docker连接到我的db docker并且网站正常工作。但我想解决这个问题。 由于这篇文章" https://support.rackspace.com/how-to/how-to-change-the-mysql-timeout-on-a-server/"我尝试增加interactive_timeout。什么都没改变......

使用composer更新项目时出现同样的错误。如果有人有想法......

config.yml

imports:
    - { resource: parameters.yml }
    - { resource: security.yml }
    - { resource: services.yml }
    - { resource: "@UserBundle/Resources/config/services.yml" }

parameters:
    locale: en

framework:
    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']
    default_locale:  "%locale%"
    trusted_hosts:   ~
    trusted_proxies: ~
    session:
        # handler_id set to null will use default session handler from php.ini
        handler_id:  ~
    fragments:       ~
    http_method_override: true

# Twig Configuration
twig:
    debug:            "%kernel.debug%"
    strict_variables: "%kernel.debug%"

# Doctrine Configuration
doctrine:
    dbal:
        driver:   pdo_mysql
        host:     "%database_host%"
        port:     "%database_port%"
        dbname:   "%database_name%"
        user:     "%database_user%"
        password: "%database_password%"
        charset:  UTF8

    orm:
        auto_generate_proxy_classes: "%kernel.debug%"
        naming_strategy: doctrine.orm.naming_strategy.underscore
        auto_mapping: true

swiftmailer:
     transport: "%mailer_transport%"
     host:      "%mailer_host%"
     username:  "%mailer_user%"
     password:  "%mailer_password%"
     spool:     { type: memory }

# FOS UserBundle Configuration
fos_user:
     db_driver: orm # other valid values are 'mongodb', 'couchdb' and 'propel'
     firewall_name: main
     user_class: UserBundle\Entity\User
     registration:
         form:
             type: UserBundle\Form\RegistrationType
     confirmation:
         from_email:
             address:        server@mail.com # put a valid mail address
             sender_name:    Confimation link
         enabled: false # pass to true to enable sending mail inscriptions
         template:   FOSUserBundle:Registration:email.txt.twig
    profile:
         form:
             type: UserBundle\Form\ProfileFormType
    resetting:
         email:
             template:   UserBundle:Reset:password_resetting.email.twig
             from_email:
                  address:        server@mail.com # put a valid mail address
                  sender_name:    Reset link

parameters.yml:

# This file is auto-generated during the composer install
parameters:
    database_host: 172.18.0.2
    database_port: 3306
    database_name: symfony
    database_user: user
    database_password: user_password
    mailer_transport: smtp
    mailer_host: 127.0.0.1
    mailer_user: null
    mailer_password: null
    secret: my_secret

security.yml

security:
    encoders:
        FOS\UserBundle\Model\UserInterface: bcrypt

    role_hierarchy:
        ROLE_ADMIN:
            - ROLE_USER

    providers:
        fos_userbundle:
            id: fos_user.user_provider.username_email

    firewalls:
        dev:
            pattern: ^/(_(profiler|wdt)|css|images|js)/
            security: false
        main:
            pattern: ^/
            form_login:
                provider: fos_userbundle
                csrf_token_generator: security.csrf.token_manager
                login_path: /
                use_forward: false
                check_path: fos_user_security_check
                failure_path: null
                default_target_path: /
                remember_me: true

            remember_me:
                secret:      %secret%
                lifetime: 3000
                path:     /
                domain:   ˜
            logout:
                path: fos_user_security_logout
                target: /
            anonymous:    true
            switch_user:  true

然后我的docker-compose.yml:

version: '2'

services:
    db:
        image: mysql
        ports:
            - 3306:3306
        volumes:
            - "./.data/db:/var/lib/mysql"
            - "./script:/stack"
        environment:
            MYSQL_ROOT_PASSWORD: user_password
        command:
            - "/stack/localdb-run.sh"
    php:
        build: php7-fpm
        ports:
            - 9000:9000
        links:
             - db:mysqldb
        volumes:
            - ./symfony:/var/www/symfony
            - ./logs/symfony:/var/www/symfony/app/logs
    nginx:
        build: nginx
           ports:
               - 80:80
        links:
           - php
        volumes_from:
           - php
        volumes:
           - ./logs/nginx/:/var/log/nginx
phpmyadmin:
    image: phpmyadmin/phpmyadmin:4.6.4-1
    ports:
        - "8080:80"
    links:
        - db

1 个答案:

答案 0 :(得分:0)

我认为这是因为您在命令中输入了类似的内容:php bin/console cache:clear

但是你使用Docker,所以你必须使用这个命令启动docker。

你的docker-compose.json中没有phpcli:)

添加它并启动此命令示例:docker-compose run --rm phpcli bin/console cache:clear