Symfony的缓存和权限出错

时间:2017-11-21 13:58:14

标签: php symfony caching

我在缓存中遇到了这个连续错误。有权限的东西,但我无法想象发生了什么。在我的本地环境中,当我去php bin/console cache:clear -e=dev时,它会返回给我

  [Symfony\Component\Filesystem\Exception\IOException]                                                                                               
  Failed to remove file "/project/var/cache/de~/pools/ORsqbHaOKl/L/K/iZULk48B-k00dzIKC2qg": unlink(/project/var/cache/de~/pools/ORsqbHaOKl/L/K/iZULk48B-k00dzIKC2qg): Permission denied.    

所以我需要先做一个chmod -R 777 var/,然后再做一个清除缓存并且它可以工作。但是当我运行网站时它会返回我

Failed to create "/project/var/cache/dev/tcpdf": mkdir(): Permission denied.

所以我需要再次制作chmod -R 777 var/

在没有删除任何内容的生产服务器中,有时会出现此错误

Warning: rename(C:\project\var\cache\prod/doctrine/orm/Proxies\__CG__AppBundleEntitySomeEntity.php.5a142ad84e8464.47105642,C:\project\var\cache\prod/doctrine/orm/Proxies\__CG__AppBundleEntitySomeEntity.php): Access is denied. (code: 5)
  vendor \ doctrine \ common \ lib \ Doctrine \ Common \ Proxy \ ProxyGenerator.php中的

错误   (第309行重命名())

    $tmpFileName = $fileName . '.' . uniqid('', true);
    file_put_contents($tmpFileName, $proxyCode);
    @chmod($tmpFileName, 0664);
    rename($tmpFileName, $fileName);
}

当地环境:debian 9 生产环境:Windows Server 2008

2 个答案:

答案 0 :(得分:2)

您需要按照this symfony文章的建议设置var文件夹权限。

在项目目录中运行以下命令,您将不会遇到有关缓存和日志的任何权限相关问题

public class AdapterUsersData extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

private Context context;
private LayoutInflater inflater;
List<UsersData> data= Collections.emptyList();
UsersData current;
int currentPos=0;

// create constructor to innitilize context and data sent from MainActivity
public AdapterUsersData(Context context, List<UsersData> data){
    this.context=context;
    inflater= LayoutInflater.from(context);
    this.data=data;
}

// Inflate the layout when viewholder created
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    View view=inflater.inflate(R.layout.container_users, parent,false);
    MyHolder holder=new MyHolder(view);
    return holder;
}

// Bind data
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {

    // Get current position of item in recyclerview to bind data and assign values from list
    final MyHolder myHolder= (MyHolder) holder;
    final UsersData current=data.get(position);
    myHolder.textFirstName.setText("First Name: " + current.fname);
    myHolder.textPassword.setText("Pass: " + current.password);
    myHolder.textLastName.setText("Last Name: " + current.lname);
    myHolder.textEmail.setText("Email. " + current.email);


}

// return total item from List
@Override
public int getItemCount() {
    return data.size();
}


class MyHolder extends RecyclerView.ViewHolder{

    TextView textFirstName;
    TextView textPassword;
    TextView textLastName;
    TextView textEmail;

    // create constructor to get widget reference
    public MyHolder(View itemView) {
        super(itemView);
        textFirstName= (TextView) itemView.findViewById(R.id.textFirstName);
        textPassword = (TextView) itemView.findViewById(R.id.textPassword);
        textLastName = (TextView) itemView.findViewById(R.id.textLastName);
        textEmail = (TextView) itemView.findViewById(R.id.textEmail);
    }

}

}

答案 1 :(得分:0)

我刚刚玩了一下,并注意到每次打电话

bin/console cache:clear --env=prod

文件夹/prod的用户将更改为正在执行呼叫的用户。脚本删除文件夹并创建一个新的文件夹,但这将是当前用户设置。

您可以使用--no-warmup选项停止脚本创建新文件夹。有了这个,我已经解决了我的问题。

bin/console cache:clear --env=prod --no-warmup

为此,您需要修复当前情况,最好删除/var/cache目录中的所有文件夹和文件。