Reputation: 904
I'm trying to wrap a custom php extension from a C library, now I have an Initializer function which initiate a specific custom connection and seems to be expensive one and i should not run it each time I call the function.
Let's suppose that I have the following in the ZEND wrapper,
PHP_FUNCTION(get_data){
conn = conn_init();
data = getdata(conn);
return data;
}
conn_init()
is an expensive call here, where should I put that function?
and can I ask users to call conn_init()
from PHP and how?
Upvotes: 2
Views: 146
Reputation: 96159
Looks like you should wrap conn
as a resource.
Then a script using your extension could look like
$conn = YOUREXT_connect($cparams);
$data[1] = YOUREXT_getdata($conn, $params[1]);
$data[2] = YOUREXT_getdata($conn, $params[2]);
$data[3] = YOUREXT_getdata($conn, $params[3]);
Upvotes: 1