何时在服务器上弃用 PROD 缓存,在本地主机上获取错误Doctrine Proxy时,所有操作均无错误地执行。两台主机上的重置DEV缓存也成功重置。
"require": {
"php": ">=5.3.3",
"symfony/symfony": "v2.7.3",
"doctrine/orm": "v2.5.0",
"doctrine/doctrine-bundle": "v1.5.1",
"twig/extensions": "v1.3.0",
"symfony/assetic-bundle": "v2.3.1",
"symfony/swiftmailer-bundle": "v2.3.8",
"symfony/monolog-bundle": "v2.7.1",
"sensio/distribution-bundle": "v3.0.30",
"sensio/framework-extra-bundle": "v3.0.10",
"incenteev/composer-parameter-handler": "v2.1.1",
"friendsofsymfony/user-bundle": "v2.0.0-alpha3",
"knplabs/knp-paginator-bundle": "2.5.0",
"gregwar/image-bundle": "v2.0.21",
"sensio/buzz-bundle": "v1.0.0",
"whiteoctober/breadcrumbs-bundle": "1.2.0",
"sonata-project/admin-bundle": "2.3.3",
"sonata-project/doctrine-orm-admin-bundle": "2.3.2",
"sonata-project/translation-bundle": "1.0.0",
"sonata-project/doctrine-extensions": "1.0.2",
"iphp/filestore-bundle" : "v0.2.5",
"sonata-project/intl-bundle": "2.2.2",
"oro/doctrine-extensions": "1.0.8",
"devcookies/signgen": "^1.0",
"gedmo/doctrine-extensions": "^2.4"
},
我的观察№1
运行控制台命令以清除 PROD 缓存:
sudo php app / console cache:clear -e prod
得到错误
PHP警告: 要求(/var/www/site.com/www/app/cache/pro_/doctrine/orm/Proxies / __ CG__AppMerchantBundleEntityProject.php): 无法打开流:没有这样的文件或目录 /var/www/site.com/www/vendor/doctrine/common/lib/Doctrine/Common/Proxy/AbstractProxyFactory.php 在209行PHP致命错误:require():需要打开失败 ' /var/www/site.com/www/app/cache/pro_/doctrine/orm/Proxies / __ CG__AppMerchantBundleEntityProject.php' (include_path ='。:/ usr / share / php:/ usr / share / pear')in /var/www/site.com/www/vendor/doctrine/common/lib/Doctrine/Common/Proxy/AbstractProxyFactory.php 209行[2016-01-29 10:30:55] php.CRITICAL:致命编译错误: require():需要打开失败 ' /var/www/site.com/www/app/cache/pro_/doctrine/orm/Proxies / __ CG__AppMerchantBundleEntityProject.php' (包含路径=':在/ usr /共享/ PHP的:在/ usr /共享/梨') {"类型":64,"文件":" /var/www/site.com/www/vendor/doctrine/common/lib/Doctrine/Common/Proxy/ AbstractProxyFactory.php""线":209,"电平":6143,"堆栈":[]} {" request_ip":"不可用"," client_ip":"不可用"} PHP致命 错误:未捕获的异常 ' Symfony的\元器件\调试\异常\ FatalErrorException'与消息 '编译错误:require():需要打开失败 ' /var/www/site.com/www/app/cache/pro_/doctrine/orm/Proxies / __ CG__AppMerchantBundleEntityProject.php' (包含路径=':在/ usr /共享/ PHP的:在/ usr /共享/梨')'在 /var/www/site.com/www/vendor/doctrine/common/lib/Doctrine/Common/Proxy/AbstractProxyFactory.php:209 堆栈跟踪:
0 {main}引自/var/www/site.com/www/vendor/doctrine/common/lib/Doctrine/Common/Proxy/AbstractProxyFactory.php
第209行
运行控制台命令以清除 DEV 缓存:
sudo php app / console cache:clear -e dev
没关系,没有错误
我的观察№2
在配置文件中,更改设置Doctrine
doctrine:
dbal:
driver: "%database_driver%"
host: "%database_host%"
port: "%database_port%"
dbname: "%database_name%"
user: "%database_user%"
password: "%database_password%"
charset: UTF8
types:
json: Sonata\Doctrine\Types\JsonType
mapping_types:
enum: string
orm:
auto_generate_proxy_classes: "%kernel.debug%"
...
更改了配置:
doctrine:
dbal:
driver: "%database_driver%"
host: "%database_host%"
port: "%database_port%"
dbname: "%database_name%"
user: "%database_user%"
password: "%database_password%"
charset: UTF8
types:
json: Sonata\Doctrine\Types\JsonType
mapping_types:
enum: string
orm:
auto_generate_proxy_classes: true
...
刷新PROD缓存而没有错误
我的观察№3
最近修改的代码实际上全部破坏并添加了两个相关实体:
项目实体
<?php
namespace App\MerchantBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use App\CoreBundle\Entity\Cashbox;
use App\PaymentBundle\Entity\Cash\Template;
use App\MerchantBundle\Entity\Project\Terminal;
/**
* Project
*
* @ORM\Table(name="merchant_projects", uniqueConstraints={@ORM\UniqueConstraint(name="id_UNIQUE", columns={"id"}), @ORM\UniqueConstraint(name="secret_key_UNIQUE", columns={"secret_key"}), @ORM\UniqueConstraint(name="merchant_id_UNIQUE", columns={"merchant_id"})})
* @ORM\Entity
*/
class Project
{
...
/**
* @ORM\OneToMany(targetEntity="\App\MerchantBundle\Entity\Project\Domain", mappedBy="project")
*/
private $domains;
...
域实体
<?php
namespace App\MerchantBundle\Entity\Project;
use Doctrine\ORM\Mapping as ORM;
/**
* Domain
*
* @ORM\Table(name="merchant_project_domains")
* @ORM\Entity
*/
class Domain
{
...
/**
* @var \App\MerchantBundle\Entity\Project
*
* @ORM\ManyToOne(targetEntity="\App\MerchantBundle\Entity\Project", inversedBy="domains")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="project_id", referencedColumnName="id")
* })
*/
private $project;
如果删除连接域实体
/**
* @var \App\MerchantBundle\Entity\Project
*/
private $project;
没关系,没有错误
答案 0 :(得分:1)
您是否尝试按
强制删除缓存rm -rf app/cache/*
然后(当然db转储它会很好)
php app/console doctrine:schema:update --force
答案 1 :(得分:0)
我找到了以下命令序列:
chmod -R 777 ./app/cache
rm -rf app/cache/*
php app/console cache:clear --env=prod --no-warmup --no-debug
php app/console cache:warmup --env=prod --no-debug
chmod -R 777 ./app/cache
php app/console doctrine:generate:entities yourBundleName --no-backup
php app/console doctrine:schema:update --force
此外,如果您使用apache,则应将正确的所有者设置为缓存文件夹:
sudo chown -R apache:apache app/cache
答案 2 :(得分:0)
找到了原因。
对于路由的动态条件,我从数据库中获取允许的域列表。为此,我使用 CompilerPassInterface 。如果表中有条目,我收到错误,如果清除缓存的表已成功清除。
我希望数据库中的数据尝试在创建者和项目实体的缓存时间之前缓存
Screen of my CompilerPass class
请告诉我如何将设置存储在数据库中,然后在胡子中使用它们进行路由?
答案 3 :(得分:0)
您清除 DEV 环境上的缓存,这还将为您创建Doctrine代理类:
bin/console cache:clear --env=dev
但是,在 PROD 环境中,人们必须预热而不是清除缓存,这会转换为以下命令:
bin/console cache:warmup --env=prod --no-debug
如果您希望您的Web服务器(Apache / Nginx /其他)能够访问缓存/日志文件,则上述其他用户对./var
权限的其他评论是显而易见且常识。因此,如果用于在终端中以交互方式清理/预热缓存,请确保始终运行以下命令(请参见下面的注释):
sudo chown -R <your-local-user>:<your-webserver-user> var/
sudo chmod -R 0770 var/
其中:
注意:如果您要通过网络清理/预热缓存 请求/操作-是的,有可能! -然后上面的chown / chmod 不需要,因为将创建这些文件夹/文件 使用正在运行的实例(网络服务器)owner:group。