How to pass resource from a Gearman worker to client

38 Views Asked by At

I have implemented connection pool in php with gearman. An old man techinque I know.

The concept is start a worker with x number of connections. the client requests a connection and worker gives that.

However when I connect to db, I get a connection resource. How can I pass the connection resource to the client. If I pass resource it gives message that object cannot be converted to the string. If I serialize it the connection resource is lost.

my code

worker.php

//start worker
//addfunction ('getdb' 'getdb')

function getdb ($job){
$data = unserialize($job->workload();
$uname=$data['uname'];
$pasword=$data['pwd'];
$con=mysqli_connect($host,$uname,$password,$db);
return $con;

}

Client code

//gearman client
$connection = client->doNormal('getdb',serialize([$uname,$pass]));

var_dump($connection)

if I do var_dump on connection I see null or string 0, How can I get resource from worker to client over here.

0

There are 0 best solutions below