1[[connection-factory]] 2=== Setting a custom ConnectionFactory 3 4The ConnectionFactory instantiates new Connection objects when requested by the 5<<connection_pool>>. A single Connection represents a single node. Since the 6client hands actual networking work over to RingPHP, the Connection's main job 7is book-keeping: Is this node alive? Did it fail a ping request? What is the 8host and port? 9 10There is little reason to provide your own ConnectionFactory, but if you need to 11do so, you need to supply an intact ConnectionFactory object to the 12`setConnectionFactory()` method. The object should implement the 13`ConnectionFactoryInterface` interface. 14 15[source,php] 16---- 17 18class MyConnectionFactory implements ConnectionFactoryInterface 19{ 20 21 public function __construct($handler, array $connectionParams, 22 SerializerInterface $serializer, 23 LoggerInterface $logger, 24 LoggerInterface $tracer) 25 { 26 // Code here 27 } 28 29 30 /** 31 * @param $hostDetails 32 * 33 * @return ConnectionInterface 34 */ 35 public function create($hostDetails) 36 { 37 // Code here...must return a Connection object 38 } 39} 40 41 42$connectionFactory = new MyConnectionFactory( 43 $handler, 44 $connectionParams, 45 $serializer, 46 $logger, 47 $tracer 48); 49 50$client = ClientBuilder::create() 51 ->setConnectionFactory($connectionFactory); 52 ->build(); 53---- 54 55As you can see, if you decide to inject your own ConnectionFactory, you take 56over the responsibility of wiring it correctly. The ConnectionFactory requires a 57working HTTP handler, serializer, logger and tracer.