php: wrap watchConnectivityState api
diff --git a/src/php/ext/grpc/channel.c b/src/php/ext/grpc/channel.c
index 8a3fe11..ebb1320 100644
--- a/src/php/ext/grpc/channel.c
+++ b/src/php/ext/grpc/channel.c
@@ -51,8 +51,10 @@
 #include <grpc/support/log.h>
 #include <grpc/grpc_security.h>
 
-#include "server.h"
+#include "completion_queue.h"
 #include "credentials.h"
+#include "server.h"
+#include "timeval.h"
 
 zend_class_entry *grpc_ce_channel;
 
@@ -225,6 +227,42 @@
 }
 
 /**
+ * Watch the connectivity state of the channel until it changed
+ * @param long The previous connectivity state of the channel
+ * @param Timeval The deadline this function should wait until
+ */
+PHP_METHOD(Channel, watchConnectivityState) {
+  wrapped_grpc_channel *channel =
+      (wrapped_grpc_channel *)zend_object_store_get_object(getThis() TSRMLS_CC);
+  long last_state;
+  zval *deadline_obj;
+  /* "lO" == 1 long 1 object */
+  if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lO",
+          &last_state, &deadline_obj, grpc_ce_timeval) == FAILURE) {
+    zend_throw_exception(spl_ce_InvalidArgumentException,
+        "watchConnectivityState expects 1 long 1 timeval",
+        1 TSRMLS_CC);
+    return;
+  }
+
+  wrapped_grpc_timeval *deadline =
+      (wrapped_grpc_timeval *)zend_object_store_get_object(
+          deadline_obj TSRMLS_CC);
+  grpc_channel_watch_connectivity_state(
+      channel->wrapped, (grpc_connectivity_state)last_state,
+      deadline->wrapped, completion_queue, NULL);
+  grpc_event event = grpc_completion_queue_pluck(
+      completion_queue, NULL,
+      gpr_inf_future(GPR_CLOCK_REALTIME));
+  if (!event.success) {
+    zend_throw_exception(spl_ce_LogicException,
+        "watchConnectivityState failed",
+        1 TSRMLS_CC);
+  }
+  return;
+}
+
+/**
  * Close the channel
  */
 PHP_METHOD(Channel, close) {
@@ -240,6 +278,7 @@
     PHP_ME(Channel, __construct, NULL, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
     PHP_ME(Channel, getTarget, NULL, ZEND_ACC_PUBLIC)
     PHP_ME(Channel, getConnectivityState, NULL, ZEND_ACC_PUBLIC)
+    PHP_ME(Channel, watchConnectivityState, NULL, ZEND_ACC_PUBLIC)
     PHP_ME(Channel, close, NULL, ZEND_ACC_PUBLIC)
     PHP_FE_END};