Spamworldpro Mini Shell
Spamworldpro


Server : Apache
System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64
User : corals ( 1002)
PHP Version : 7.4.33
Disable Function : exec,passthru,shell_exec,system
Directory :  /home/corals/old/vendor/elasticsearch/elasticsearch/docs/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/old/vendor/elasticsearch/elasticsearch/docs/connection-factory.asciidoc
[[connection-factory]]
=== Setting a custom ConnectionFactory

The ConnectionFactory instantiates new Connection objects when requested by the 
<<connection_pool>>. A single Connection represents a single node. Since the 
client hands actual networking work over to RingPHP, the Connection's main job 
is book-keeping: Is this node alive? Did it fail a ping request? What is the 
host and port?

There is little reason to provide your own ConnectionFactory, but if you need to 
do so, you need to supply an intact ConnectionFactory object to the 
`setConnectionFactory()` method. The object should implement the 
`ConnectionFactoryInterface` interface.

[source,php]
----

class MyConnectionFactory implements ConnectionFactoryInterface
{

    public function __construct($handler, array $connectionParams,
                                SerializerInterface $serializer,
                                LoggerInterface $logger,
                                LoggerInterface $tracer)
    {
       // Code here
    }


    /**
     * @param $hostDetails
     *
     * @return ConnectionInterface
     */
    public function create($hostDetails)
    {
        // Code here...must return a Connection object
    }
}


$connectionFactory = new MyConnectionFactory(
    $handler,
    $connectionParams,
    $serializer,
    $logger,
    $tracer
);

$client = ClientBuilder::create()
            ->setConnectionFactory($connectionFactory);
            ->build();
----

As you can see, if you decide to inject your own ConnectionFactory, you take 
over the responsibility of wiring it correctly. The ConnectionFactory requires a 
working HTTP handler, serializer, logger and tracer.

Spamworldpro Mini