[getdns-api] PHP Language Bindings and Async Event Management

Hollenbeck, Scott shollenbeck at verisign.com
Fri Apr 17 20:27:20 CEST 2015


In the very near future you should all be able to see the 0.1.0 version of the PHP language bindings that I've been working on. There's one bit that is still confusing me a bit, so I thought I'd throw this out to everyone for thoughts.

The code currently implements asynchronous operations using the same event management functions that are used in the example code published here:

http://getdnsapi.net/spec.html

That is, my function wrapper calls these functions in sequence:

struct event_base *this_event_base;
this_event_base = event_base_new();
(void)getdns_extension_set_libevent_base(this_context, this_event_base);
dispatch_return = event_base_dispatch(this_event_base);
event_base_free(this_event_base);

This means that the event base gets created and destroyed with every call to php_getdns_address() and the other functions like it. That works, but it seems to be producing behavior that looks just like the synchronous functions.

Another one of the issues I've run into is that I can't figure out a good way to wrap the getdns_context_set_eventloop() function. It ultimately requires a pointer to a getdns_eventloop record. I can create a record with a VMT in my wrapping code, but I can't think of anything that a PHP client could pass to my code to do in the different callback functions - and if there is something useful I have no way to make it available to the callbacks.

So then I started thinking about stripping out the event functions provided by getdns and using the PHP libevent extension (http://php.net/manual/en/book.libevent.php). A PHP client could be responsible for making the appropriate library calls to create the event base, call php_getdns_address(), run the loop, and eventually free the event base. The problem with this approach is that I can't find a way to get the event base created by a PHP client into the getdns context. getdns_extension_set_libevent_base() requires a pointer to an event_base record, and I don't have access to a PHP variable that includes everything needed to populate that record. The PHP variable that holds the result of a call to PHP's event_base_new() is (as I understand it) a resource that's used to share information between the PHP client and the libevent extension, It doesn't appear to be something that I can break apart or decode intelligently.

So, what's the best way to approach the event management operations needed for asynchronous processing?

Scott




_______________________________________________
getdns-api mailing list
getdns-api at vpnc.org



More information about the spec mailing list