|  | @@ -49,7 +49,8 @@
 | 
	
		
			
				|  |  |  #include <ext/standard/info.h>
 | 
	
		
			
				|  |  |  #include "php_grpc.h"
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -// ZEND_DECLARE_MODULE_GLOBALS(grpc)
 | 
	
		
			
				|  |  | +ZEND_DECLARE_MODULE_GLOBALS(grpc)
 | 
	
		
			
				|  |  | +static PHP_GINIT_FUNCTION(grpc);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  /* {{{ grpc_functions[]
 | 
	
		
			
				|  |  |   *
 | 
	
	
		
			
				|  | @@ -70,13 +71,17 @@ zend_module_entry grpc_module_entry = {
 | 
	
		
			
				|  |  |    grpc_functions,
 | 
	
		
			
				|  |  |    PHP_MINIT(grpc),
 | 
	
		
			
				|  |  |    PHP_MSHUTDOWN(grpc),
 | 
	
		
			
				|  |  | -  NULL,
 | 
	
		
			
				|  |  | +  PHP_RINIT(grpc),
 | 
	
		
			
				|  |  |    NULL,
 | 
	
		
			
				|  |  |    PHP_MINFO(grpc),
 | 
	
		
			
				|  |  |  #if ZEND_MODULE_API_NO >= 20010901
 | 
	
		
			
				|  |  |    PHP_GRPC_VERSION,
 | 
	
		
			
				|  |  |  #endif
 | 
	
		
			
				|  |  | -  STANDARD_MODULE_PROPERTIES};
 | 
	
		
			
				|  |  | +  PHP_MODULE_GLOBALS(grpc),
 | 
	
		
			
				|  |  | +  PHP_GINIT(grpc),
 | 
	
		
			
				|  |  | +  NULL,
 | 
	
		
			
				|  |  | +  NULL,
 | 
	
		
			
				|  |  | +  STANDARD_MODULE_PROPERTIES_EX};
 | 
	
		
			
				|  |  |  /* }}} */
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  #ifdef COMPILE_DL_GRPC
 | 
	
	
		
			
				|  | @@ -114,7 +119,6 @@ PHP_MINIT_FUNCTION(grpc) {
 | 
	
		
			
				|  |  |       REGISTER_INI_ENTRIES();
 | 
	
		
			
				|  |  |    */
 | 
	
		
			
				|  |  |    /* Register call error constants */
 | 
	
		
			
				|  |  | -  grpc_init();
 | 
	
		
			
				|  |  |    REGISTER_LONG_CONSTANT("Grpc\\CALL_OK", GRPC_CALL_OK,
 | 
	
		
			
				|  |  |                           CONST_CS | CONST_PERSISTENT);
 | 
	
		
			
				|  |  |    REGISTER_LONG_CONSTANT("Grpc\\CALL_ERROR", GRPC_CALL_ERROR,
 | 
	
	
		
			
				|  | @@ -242,7 +246,6 @@ PHP_MINIT_FUNCTION(grpc) {
 | 
	
		
			
				|  |  |    grpc_init_channel_credentials(TSRMLS_C);
 | 
	
		
			
				|  |  |    grpc_init_call_credentials(TSRMLS_C);
 | 
	
		
			
				|  |  |    grpc_init_server_credentials(TSRMLS_C);
 | 
	
		
			
				|  |  | -  grpc_php_init_completion_queue(TSRMLS_C);
 | 
	
		
			
				|  |  |    return SUCCESS;
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  /* }}} */
 | 
	
	
		
			
				|  | @@ -255,9 +258,12 @@ PHP_MSHUTDOWN_FUNCTION(grpc) {
 | 
	
		
			
				|  |  |    */
 | 
	
		
			
				|  |  |    // WARNING: This function IS being called by PHP when the extension
 | 
	
		
			
				|  |  |    // is unloaded but the logs were somehow suppressed.
 | 
	
		
			
				|  |  | -  grpc_shutdown_timeval(TSRMLS_C);
 | 
	
		
			
				|  |  | -  grpc_php_shutdown_completion_queue(TSRMLS_C);
 | 
	
		
			
				|  |  | -  grpc_shutdown();
 | 
	
		
			
				|  |  | +  if (GRPC_G(initialized)) {
 | 
	
		
			
				|  |  | +    grpc_shutdown_timeval(TSRMLS_C);
 | 
	
		
			
				|  |  | +    grpc_php_shutdown_completion_queue(TSRMLS_C);
 | 
	
		
			
				|  |  | +    grpc_shutdown();
 | 
	
		
			
				|  |  | +    GRPC_G(initialized) = 0;
 | 
	
		
			
				|  |  | +  }
 | 
	
		
			
				|  |  |    return SUCCESS;
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  /* }}} */
 | 
	
	
		
			
				|  | @@ -274,6 +280,26 @@ PHP_MINFO_FUNCTION(grpc) {
 | 
	
		
			
				|  |  |    */
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  /* }}} */
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +/* {{{ PHP_RINIT_FUNCTION
 | 
	
		
			
				|  |  | + */
 | 
	
		
			
				|  |  | +PHP_RINIT_FUNCTION(grpc) {
 | 
	
		
			
				|  |  | +  if (!GRPC_G(initialized)) {
 | 
	
		
			
				|  |  | +    grpc_init();
 | 
	
		
			
				|  |  | +    grpc_php_init_completion_queue(TSRMLS_C);
 | 
	
		
			
				|  |  | +    GRPC_G(initialized) = 1;
 | 
	
		
			
				|  |  | +  }
 | 
	
		
			
				|  |  | +  return SUCCESS;
 | 
	
		
			
				|  |  | +}
 | 
	
		
			
				|  |  | +/* }}} */
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +/* {{{ PHP_GINIT_FUNCTION
 | 
	
		
			
				|  |  | + */
 | 
	
		
			
				|  |  | +static PHP_GINIT_FUNCTION(grpc) {
 | 
	
		
			
				|  |  | +  grpc_globals->initialized = 0;
 | 
	
		
			
				|  |  | +}
 | 
	
		
			
				|  |  | +/* }}} */
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  /* The previous line is meant for vim and emacs, so it can correctly fold and
 | 
	
		
			
				|  |  |     unfold functions in source code. See the corresponding marks just before
 | 
	
		
			
				|  |  |     function definition, where the functions purpose is also documented. Please
 |