1. A proxy object (proxy) is established between the client and the entity. All operations performed by the client to the entity are delegated to the proxy object, hiding the implementation details of the entity.

  2. Proxy can also be deployed to a separate server from business code, where tasks are delegated through RPC.

// Proxy interface
interface Proxy
{
    public function getUserName($id);

    public function setUserName($id.$newName);
}

// User operation agent implementation
class UserProxy implements Proxy
{
    / / read operation
    public function getUserName($id)
    {
        return Factory::getDataBase('slave')->find($id);
    }

    / / write operations
    public function setUserName($id.$newName)
    {
        return Factory::getDataBase('master')->data(['name'= >$newName])->where(['id'= >$id])}}// Proxy mode: primary/secondary database, set primary/secondary read/write Settings through proxy.
$proxy = new UserProxy();
$proxy->getUserName(1);
$proxy->setUserName(1.'Joe');
Copy the code

The above content hopes to help you, more free PHP factory PDF, PHP advanced architecture video materials, PHP wonderful good article can be wechat search concerns: PHP open source community

2021 Jinsanyin four big factory interview real questions collection, must see!

Four years of PHP technical articles collation collection – PHP framework

A collection of four years’ worth of PHP technical articles – Microservices Architecture

Distributed Architecture is a four-year collection of PHP technical articles

Four years of PHP technical essays – High Concurrency scenarios

Four years of elite PHP technical article collation collection – database