Craig Tiller | 1a61b17 | 2015-02-16 11:53:47 -0800 | [diff] [blame] | 1 | /* |
| 2 | * |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 3 | * Copyright 2015 gRPC authors. |
Craig Tiller | 1a61b17 | 2015-02-16 11:53:47 -0800 | [diff] [blame] | 4 | * |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at |
Craig Tiller | 1a61b17 | 2015-02-16 11:53:47 -0800 | [diff] [blame] | 8 | * |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
Craig Tiller | 1a61b17 | 2015-02-16 11:53:47 -0800 | [diff] [blame] | 10 | * |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
Craig Tiller | 1a61b17 | 2015-02-16 11:53:47 -0800 | [diff] [blame] | 16 | * |
| 17 | */ |
| 18 | |
thinkerou | 771c205 | 2018-05-15 10:37:43 +0800 | [diff] [blame^] | 19 | #include "php_grpc.h" |
| 20 | |
mlumish | b892a27 | 2014-12-09 16:28:23 -0800 | [diff] [blame] | 21 | #include "call.h" |
| 22 | #include "channel.h" |
| 23 | #include "server.h" |
mlumish | b892a27 | 2014-12-09 16:28:23 -0800 | [diff] [blame] | 24 | #include "timeval.h" |
Stanley Cheung | 9c0b35e | 2015-10-21 17:07:56 -0700 | [diff] [blame] | 25 | #include "channel_credentials.h" |
Stanley Cheung | aeea102 | 2015-10-21 17:00:49 -0700 | [diff] [blame] | 26 | #include "call_credentials.h" |
mlumish | b892a27 | 2014-12-09 16:28:23 -0800 | [diff] [blame] | 27 | #include "server_credentials.h" |
murgatroid99 | 268acd5 | 2015-05-14 15:05:00 -0700 | [diff] [blame] | 28 | #include "completion_queue.h" |
mlumish | b892a27 | 2014-12-09 16:28:23 -0800 | [diff] [blame] | 29 | |
Stanley Cheung | 5d55948 | 2017-08-22 13:15:01 -0700 | [diff] [blame] | 30 | ZEND_DECLARE_MODULE_GLOBALS(grpc) |
| 31 | static PHP_GINIT_FUNCTION(grpc); |
ZhouyihaiDing | 5c77035 | 2018-04-09 13:20:31 -0700 | [diff] [blame] | 32 | HashTable grpc_persistent_list; |
ZhouyihaiDing | 9ef881e | 2018-04-12 16:43:33 -0700 | [diff] [blame] | 33 | HashTable grpc_target_upper_bound_map; |
mlumish | b892a27 | 2014-12-09 16:28:23 -0800 | [diff] [blame] | 34 | /* {{{ grpc_functions[] |
| 35 | * |
| 36 | * Every user visible function must have an entry in grpc_functions[]. |
| 37 | */ |
| 38 | const zend_function_entry grpc_functions[] = { |
Craig Tiller | b5dcec5 | 2015-01-13 11:13:42 -0800 | [diff] [blame] | 39 | PHP_FE_END /* Must be the last line in grpc_functions[] */ |
mlumish | b892a27 | 2014-12-09 16:28:23 -0800 | [diff] [blame] | 40 | }; |
| 41 | /* }}} */ |
| 42 | |
| 43 | /* {{{ grpc_module_entry |
| 44 | */ |
| 45 | zend_module_entry grpc_module_entry = { |
thinkerou | a3730b7 | 2016-07-20 16:59:54 +0800 | [diff] [blame] | 46 | STANDARD_MODULE_HEADER, |
thinkerou | a3730b7 | 2016-07-20 16:59:54 +0800 | [diff] [blame] | 47 | "grpc", |
| 48 | grpc_functions, |
| 49 | PHP_MINIT(grpc), |
| 50 | PHP_MSHUTDOWN(grpc), |
Stanley Cheung | 5d55948 | 2017-08-22 13:15:01 -0700 | [diff] [blame] | 51 | PHP_RINIT(grpc), |
thinkerou | a3730b7 | 2016-07-20 16:59:54 +0800 | [diff] [blame] | 52 | NULL, |
| 53 | PHP_MINFO(grpc), |
thinkerou | a3730b7 | 2016-07-20 16:59:54 +0800 | [diff] [blame] | 54 | PHP_GRPC_VERSION, |
Stanley Cheung | 5d55948 | 2017-08-22 13:15:01 -0700 | [diff] [blame] | 55 | PHP_MODULE_GLOBALS(grpc), |
| 56 | PHP_GINIT(grpc), |
| 57 | NULL, |
| 58 | NULL, |
| 59 | STANDARD_MODULE_PROPERTIES_EX}; |
mlumish | b892a27 | 2014-12-09 16:28:23 -0800 | [diff] [blame] | 60 | /* }}} */ |
| 61 | |
| 62 | #ifdef COMPILE_DL_GRPC |
| 63 | ZEND_GET_MODULE(grpc) |
| 64 | #endif |
| 65 | |
| 66 | /* {{{ PHP_INI |
| 67 | */ |
| 68 | /* Remove comments and fill if you need to have entries in php.ini |
thinkerou | a3730b7 | 2016-07-20 16:59:54 +0800 | [diff] [blame] | 69 | PHP_INI_BEGIN() |
| 70 | STD_PHP_INI_ENTRY("grpc.global_value", "42", PHP_INI_ALL, OnUpdateLong, |
| 71 | global_value, zend_grpc_globals, grpc_globals) |
| 72 | STD_PHP_INI_ENTRY("grpc.global_string", "foobar", PHP_INI_ALL, |
| 73 | OnUpdateString, global_string, zend_grpc_globals, |
| 74 | grpc_globals) |
| 75 | PHP_INI_END() |
mlumish | b892a27 | 2014-12-09 16:28:23 -0800 | [diff] [blame] | 76 | */ |
| 77 | /* }}} */ |
| 78 | |
| 79 | /* {{{ php_grpc_init_globals |
| 80 | */ |
| 81 | /* Uncomment this function if you have INI entries |
thinkerou | a3730b7 | 2016-07-20 16:59:54 +0800 | [diff] [blame] | 82 | static void php_grpc_init_globals(zend_grpc_globals *grpc_globals) |
| 83 | { |
| 84 | grpc_globals->global_value = 0; |
| 85 | grpc_globals->global_string = NULL; |
| 86 | } |
mlumish | b892a27 | 2014-12-09 16:28:23 -0800 | [diff] [blame] | 87 | */ |
| 88 | /* }}} */ |
| 89 | |
| 90 | /* {{{ PHP_MINIT_FUNCTION |
| 91 | */ |
Craig Tiller | b5dcec5 | 2015-01-13 11:13:42 -0800 | [diff] [blame] | 92 | PHP_MINIT_FUNCTION(grpc) { |
| 93 | /* If you have INI entries, uncomment these lines |
thinkerou | a3730b7 | 2016-07-20 16:59:54 +0800 | [diff] [blame] | 94 | REGISTER_INI_ENTRIES(); |
Craig Tiller | b5dcec5 | 2015-01-13 11:13:42 -0800 | [diff] [blame] | 95 | */ |
| 96 | /* Register call error constants */ |
Hannes Magnusson | bd52ac4 | 2015-10-06 15:26:41 -0700 | [diff] [blame] | 97 | REGISTER_LONG_CONSTANT("Grpc\\CALL_OK", GRPC_CALL_OK, |
| 98 | CONST_CS | CONST_PERSISTENT); |
| 99 | REGISTER_LONG_CONSTANT("Grpc\\CALL_ERROR", GRPC_CALL_ERROR, |
| 100 | CONST_CS | CONST_PERSISTENT); |
Craig Tiller | b5dcec5 | 2015-01-13 11:13:42 -0800 | [diff] [blame] | 101 | REGISTER_LONG_CONSTANT("Grpc\\CALL_ERROR_NOT_ON_SERVER", |
Hannes Magnusson | bd52ac4 | 2015-10-06 15:26:41 -0700 | [diff] [blame] | 102 | GRPC_CALL_ERROR_NOT_ON_SERVER, |
| 103 | CONST_CS | CONST_PERSISTENT); |
Craig Tiller | b5dcec5 | 2015-01-13 11:13:42 -0800 | [diff] [blame] | 104 | REGISTER_LONG_CONSTANT("Grpc\\CALL_ERROR_NOT_ON_CLIENT", |
Hannes Magnusson | bd52ac4 | 2015-10-06 15:26:41 -0700 | [diff] [blame] | 105 | GRPC_CALL_ERROR_NOT_ON_CLIENT, |
| 106 | CONST_CS | CONST_PERSISTENT); |
Craig Tiller | b5dcec5 | 2015-01-13 11:13:42 -0800 | [diff] [blame] | 107 | REGISTER_LONG_CONSTANT("Grpc\\CALL_ERROR_ALREADY_INVOKED", |
Hannes Magnusson | bd52ac4 | 2015-10-06 15:26:41 -0700 | [diff] [blame] | 108 | GRPC_CALL_ERROR_ALREADY_INVOKED, |
| 109 | CONST_CS | CONST_PERSISTENT); |
Craig Tiller | b5dcec5 | 2015-01-13 11:13:42 -0800 | [diff] [blame] | 110 | REGISTER_LONG_CONSTANT("Grpc\\CALL_ERROR_NOT_INVOKED", |
Hannes Magnusson | bd52ac4 | 2015-10-06 15:26:41 -0700 | [diff] [blame] | 111 | GRPC_CALL_ERROR_NOT_INVOKED, |
| 112 | CONST_CS | CONST_PERSISTENT); |
Craig Tiller | b5dcec5 | 2015-01-13 11:13:42 -0800 | [diff] [blame] | 113 | REGISTER_LONG_CONSTANT("Grpc\\CALL_ERROR_ALREADY_FINISHED", |
Hannes Magnusson | bd52ac4 | 2015-10-06 15:26:41 -0700 | [diff] [blame] | 114 | GRPC_CALL_ERROR_ALREADY_FINISHED, |
| 115 | CONST_CS | CONST_PERSISTENT); |
Craig Tiller | b5dcec5 | 2015-01-13 11:13:42 -0800 | [diff] [blame] | 116 | REGISTER_LONG_CONSTANT("Grpc\\CALL_ERROR_TOO_MANY_OPERATIONS", |
Hannes Magnusson | bd52ac4 | 2015-10-06 15:26:41 -0700 | [diff] [blame] | 117 | GRPC_CALL_ERROR_TOO_MANY_OPERATIONS, |
| 118 | CONST_CS | CONST_PERSISTENT); |
Craig Tiller | b5dcec5 | 2015-01-13 11:13:42 -0800 | [diff] [blame] | 119 | REGISTER_LONG_CONSTANT("Grpc\\CALL_ERROR_INVALID_FLAGS", |
Hannes Magnusson | bd52ac4 | 2015-10-06 15:26:41 -0700 | [diff] [blame] | 120 | GRPC_CALL_ERROR_INVALID_FLAGS, |
| 121 | CONST_CS | CONST_PERSISTENT); |
mlumish | b892a27 | 2014-12-09 16:28:23 -0800 | [diff] [blame] | 122 | |
Craig Tiller | b5dcec5 | 2015-01-13 11:13:42 -0800 | [diff] [blame] | 123 | /* Register flag constants */ |
| 124 | REGISTER_LONG_CONSTANT("Grpc\\WRITE_BUFFER_HINT", GRPC_WRITE_BUFFER_HINT, |
Hannes Magnusson | bd52ac4 | 2015-10-06 15:26:41 -0700 | [diff] [blame] | 125 | CONST_CS | CONST_PERSISTENT); |
Craig Tiller | b5dcec5 | 2015-01-13 11:13:42 -0800 | [diff] [blame] | 126 | REGISTER_LONG_CONSTANT("Grpc\\WRITE_NO_COMPRESS", GRPC_WRITE_NO_COMPRESS, |
Hannes Magnusson | bd52ac4 | 2015-10-06 15:26:41 -0700 | [diff] [blame] | 127 | CONST_CS | CONST_PERSISTENT); |
mlumish | b892a27 | 2014-12-09 16:28:23 -0800 | [diff] [blame] | 128 | |
Craig Tiller | b5dcec5 | 2015-01-13 11:13:42 -0800 | [diff] [blame] | 129 | /* Register status constants */ |
Hannes Magnusson | bd52ac4 | 2015-10-06 15:26:41 -0700 | [diff] [blame] | 130 | REGISTER_LONG_CONSTANT("Grpc\\STATUS_OK", GRPC_STATUS_OK, |
| 131 | CONST_CS | CONST_PERSISTENT); |
Craig Tiller | b5dcec5 | 2015-01-13 11:13:42 -0800 | [diff] [blame] | 132 | REGISTER_LONG_CONSTANT("Grpc\\STATUS_CANCELLED", GRPC_STATUS_CANCELLED, |
Hannes Magnusson | bd52ac4 | 2015-10-06 15:26:41 -0700 | [diff] [blame] | 133 | CONST_CS | CONST_PERSISTENT); |
| 134 | REGISTER_LONG_CONSTANT("Grpc\\STATUS_UNKNOWN", GRPC_STATUS_UNKNOWN, |
| 135 | CONST_CS | CONST_PERSISTENT); |
Craig Tiller | b5dcec5 | 2015-01-13 11:13:42 -0800 | [diff] [blame] | 136 | REGISTER_LONG_CONSTANT("Grpc\\STATUS_INVALID_ARGUMENT", |
Hannes Magnusson | bd52ac4 | 2015-10-06 15:26:41 -0700 | [diff] [blame] | 137 | GRPC_STATUS_INVALID_ARGUMENT, |
Stanley Cheung | 6d3f9ac | 2015-10-07 13:42:10 -0700 | [diff] [blame] | 138 | CONST_CS | CONST_PERSISTENT); |
Craig Tiller | b5dcec5 | 2015-01-13 11:13:42 -0800 | [diff] [blame] | 139 | REGISTER_LONG_CONSTANT("Grpc\\STATUS_DEADLINE_EXCEEDED", |
Hannes Magnusson | bd52ac4 | 2015-10-06 15:26:41 -0700 | [diff] [blame] | 140 | GRPC_STATUS_DEADLINE_EXCEEDED, |
| 141 | CONST_CS | CONST_PERSISTENT); |
Craig Tiller | b5dcec5 | 2015-01-13 11:13:42 -0800 | [diff] [blame] | 142 | REGISTER_LONG_CONSTANT("Grpc\\STATUS_NOT_FOUND", GRPC_STATUS_NOT_FOUND, |
Hannes Magnusson | bd52ac4 | 2015-10-06 15:26:41 -0700 | [diff] [blame] | 143 | CONST_CS | CONST_PERSISTENT); |
Craig Tiller | b5dcec5 | 2015-01-13 11:13:42 -0800 | [diff] [blame] | 144 | REGISTER_LONG_CONSTANT("Grpc\\STATUS_ALREADY_EXISTS", |
Hannes Magnusson | bd52ac4 | 2015-10-06 15:26:41 -0700 | [diff] [blame] | 145 | GRPC_STATUS_ALREADY_EXISTS, |
| 146 | CONST_CS | CONST_PERSISTENT); |
Craig Tiller | b5dcec5 | 2015-01-13 11:13:42 -0800 | [diff] [blame] | 147 | REGISTER_LONG_CONSTANT("Grpc\\STATUS_PERMISSION_DENIED", |
Hannes Magnusson | bd52ac4 | 2015-10-06 15:26:41 -0700 | [diff] [blame] | 148 | GRPC_STATUS_PERMISSION_DENIED, |
| 149 | CONST_CS | CONST_PERSISTENT); |
Craig Tiller | b5dcec5 | 2015-01-13 11:13:42 -0800 | [diff] [blame] | 150 | REGISTER_LONG_CONSTANT("Grpc\\STATUS_UNAUTHENTICATED", |
Hannes Magnusson | bd52ac4 | 2015-10-06 15:26:41 -0700 | [diff] [blame] | 151 | GRPC_STATUS_UNAUTHENTICATED, |
| 152 | CONST_CS | CONST_PERSISTENT); |
Craig Tiller | b5dcec5 | 2015-01-13 11:13:42 -0800 | [diff] [blame] | 153 | REGISTER_LONG_CONSTANT("Grpc\\STATUS_RESOURCE_EXHAUSTED", |
Hannes Magnusson | bd52ac4 | 2015-10-06 15:26:41 -0700 | [diff] [blame] | 154 | GRPC_STATUS_RESOURCE_EXHAUSTED, |
| 155 | CONST_CS | CONST_PERSISTENT); |
Craig Tiller | b5dcec5 | 2015-01-13 11:13:42 -0800 | [diff] [blame] | 156 | REGISTER_LONG_CONSTANT("Grpc\\STATUS_FAILED_PRECONDITION", |
Hannes Magnusson | bd52ac4 | 2015-10-06 15:26:41 -0700 | [diff] [blame] | 157 | GRPC_STATUS_FAILED_PRECONDITION, |
| 158 | CONST_CS | CONST_PERSISTENT); |
| 159 | REGISTER_LONG_CONSTANT("Grpc\\STATUS_ABORTED", GRPC_STATUS_ABORTED, |
| 160 | CONST_CS | CONST_PERSISTENT); |
Stanley Cheung | 6d3f9ac | 2015-10-07 13:42:10 -0700 | [diff] [blame] | 161 | REGISTER_LONG_CONSTANT("Grpc\\STATUS_OUT_OF_RANGE", |
| 162 | GRPC_STATUS_OUT_OF_RANGE, |
Hannes Magnusson | bd52ac4 | 2015-10-06 15:26:41 -0700 | [diff] [blame] | 163 | CONST_CS | CONST_PERSISTENT); |
Craig Tiller | b5dcec5 | 2015-01-13 11:13:42 -0800 | [diff] [blame] | 164 | REGISTER_LONG_CONSTANT("Grpc\\STATUS_UNIMPLEMENTED", |
Hannes Magnusson | bd52ac4 | 2015-10-06 15:26:41 -0700 | [diff] [blame] | 165 | GRPC_STATUS_UNIMPLEMENTED, |
| 166 | CONST_CS | CONST_PERSISTENT); |
Craig Tiller | b5dcec5 | 2015-01-13 11:13:42 -0800 | [diff] [blame] | 167 | REGISTER_LONG_CONSTANT("Grpc\\STATUS_INTERNAL", GRPC_STATUS_INTERNAL, |
Hannes Magnusson | bd52ac4 | 2015-10-06 15:26:41 -0700 | [diff] [blame] | 168 | CONST_CS | CONST_PERSISTENT); |
Craig Tiller | b5dcec5 | 2015-01-13 11:13:42 -0800 | [diff] [blame] | 169 | REGISTER_LONG_CONSTANT("Grpc\\STATUS_UNAVAILABLE", GRPC_STATUS_UNAVAILABLE, |
Hannes Magnusson | bd52ac4 | 2015-10-06 15:26:41 -0700 | [diff] [blame] | 170 | CONST_CS | CONST_PERSISTENT); |
Craig Tiller | b5dcec5 | 2015-01-13 11:13:42 -0800 | [diff] [blame] | 171 | REGISTER_LONG_CONSTANT("Grpc\\STATUS_DATA_LOSS", GRPC_STATUS_DATA_LOSS, |
Hannes Magnusson | bd52ac4 | 2015-10-06 15:26:41 -0700 | [diff] [blame] | 172 | CONST_CS | CONST_PERSISTENT); |
mlumish | b892a27 | 2014-12-09 16:28:23 -0800 | [diff] [blame] | 173 | |
murgatroid99 | afd541c | 2015-03-03 18:16:09 -0800 | [diff] [blame] | 174 | /* Register op type constants */ |
| 175 | REGISTER_LONG_CONSTANT("Grpc\\OP_SEND_INITIAL_METADATA", |
Hannes Magnusson | bd52ac4 | 2015-10-06 15:26:41 -0700 | [diff] [blame] | 176 | GRPC_OP_SEND_INITIAL_METADATA, |
| 177 | CONST_CS | CONST_PERSISTENT); |
murgatroid99 | afd541c | 2015-03-03 18:16:09 -0800 | [diff] [blame] | 178 | REGISTER_LONG_CONSTANT("Grpc\\OP_SEND_MESSAGE", |
Hannes Magnusson | bd52ac4 | 2015-10-06 15:26:41 -0700 | [diff] [blame] | 179 | GRPC_OP_SEND_MESSAGE, |
| 180 | CONST_CS | CONST_PERSISTENT); |
murgatroid99 | afd541c | 2015-03-03 18:16:09 -0800 | [diff] [blame] | 181 | REGISTER_LONG_CONSTANT("Grpc\\OP_SEND_CLOSE_FROM_CLIENT", |
Hannes Magnusson | bd52ac4 | 2015-10-06 15:26:41 -0700 | [diff] [blame] | 182 | GRPC_OP_SEND_CLOSE_FROM_CLIENT, |
| 183 | CONST_CS | CONST_PERSISTENT); |
murgatroid99 | afd541c | 2015-03-03 18:16:09 -0800 | [diff] [blame] | 184 | REGISTER_LONG_CONSTANT("Grpc\\OP_SEND_STATUS_FROM_SERVER", |
Hannes Magnusson | bd52ac4 | 2015-10-06 15:26:41 -0700 | [diff] [blame] | 185 | GRPC_OP_SEND_STATUS_FROM_SERVER, |
| 186 | CONST_CS | CONST_PERSISTENT); |
murgatroid99 | afd541c | 2015-03-03 18:16:09 -0800 | [diff] [blame] | 187 | REGISTER_LONG_CONSTANT("Grpc\\OP_RECV_INITIAL_METADATA", |
Hannes Magnusson | bd52ac4 | 2015-10-06 15:26:41 -0700 | [diff] [blame] | 188 | GRPC_OP_RECV_INITIAL_METADATA, |
| 189 | CONST_CS | CONST_PERSISTENT); |
murgatroid99 | afd541c | 2015-03-03 18:16:09 -0800 | [diff] [blame] | 190 | REGISTER_LONG_CONSTANT("Grpc\\OP_RECV_MESSAGE", |
Stanley Cheung | 6d3f9ac | 2015-10-07 13:42:10 -0700 | [diff] [blame] | 191 | GRPC_OP_RECV_MESSAGE, |
| 192 | CONST_CS | CONST_PERSISTENT); |
murgatroid99 | afd541c | 2015-03-03 18:16:09 -0800 | [diff] [blame] | 193 | REGISTER_LONG_CONSTANT("Grpc\\OP_RECV_STATUS_ON_CLIENT", |
Hannes Magnusson | bd52ac4 | 2015-10-06 15:26:41 -0700 | [diff] [blame] | 194 | GRPC_OP_RECV_STATUS_ON_CLIENT, |
| 195 | CONST_CS | CONST_PERSISTENT); |
murgatroid99 | afd541c | 2015-03-03 18:16:09 -0800 | [diff] [blame] | 196 | REGISTER_LONG_CONSTANT("Grpc\\OP_RECV_CLOSE_ON_SERVER", |
Hannes Magnusson | bd52ac4 | 2015-10-06 15:26:41 -0700 | [diff] [blame] | 197 | GRPC_OP_RECV_CLOSE_ON_SERVER, |
| 198 | CONST_CS | CONST_PERSISTENT); |
murgatroid99 | afd541c | 2015-03-03 18:16:09 -0800 | [diff] [blame] | 199 | |
Stanley Cheung | e63354a | 2015-08-10 15:46:42 -0700 | [diff] [blame] | 200 | /* Register connectivity state constants */ |
| 201 | REGISTER_LONG_CONSTANT("Grpc\\CHANNEL_IDLE", |
Stanley Cheung | 6d3f9ac | 2015-10-07 13:42:10 -0700 | [diff] [blame] | 202 | GRPC_CHANNEL_IDLE, |
| 203 | CONST_CS | CONST_PERSISTENT); |
Stanley Cheung | e63354a | 2015-08-10 15:46:42 -0700 | [diff] [blame] | 204 | REGISTER_LONG_CONSTANT("Grpc\\CHANNEL_CONNECTING", |
Stanley Cheung | 6d3f9ac | 2015-10-07 13:42:10 -0700 | [diff] [blame] | 205 | GRPC_CHANNEL_CONNECTING, |
| 206 | CONST_CS | CONST_PERSISTENT); |
Stanley Cheung | e63354a | 2015-08-10 15:46:42 -0700 | [diff] [blame] | 207 | REGISTER_LONG_CONSTANT("Grpc\\CHANNEL_READY", |
Stanley Cheung | 6d3f9ac | 2015-10-07 13:42:10 -0700 | [diff] [blame] | 208 | GRPC_CHANNEL_READY, |
| 209 | CONST_CS | CONST_PERSISTENT); |
Stanley Cheung | e63354a | 2015-08-10 15:46:42 -0700 | [diff] [blame] | 210 | REGISTER_LONG_CONSTANT("Grpc\\CHANNEL_TRANSIENT_FAILURE", |
Hannes Magnusson | bd52ac4 | 2015-10-06 15:26:41 -0700 | [diff] [blame] | 211 | GRPC_CHANNEL_TRANSIENT_FAILURE, |
| 212 | CONST_CS | CONST_PERSISTENT); |
Stanley Cheung | e63354a | 2015-08-10 15:46:42 -0700 | [diff] [blame] | 213 | REGISTER_LONG_CONSTANT("Grpc\\CHANNEL_FATAL_FAILURE", |
Craig Tiller | 48ed92e | 2016-06-02 11:07:12 -0700 | [diff] [blame] | 214 | GRPC_CHANNEL_SHUTDOWN, |
Hannes Magnusson | bd52ac4 | 2015-10-06 15:26:41 -0700 | [diff] [blame] | 215 | CONST_CS | CONST_PERSISTENT); |
Stanley Cheung | e63354a | 2015-08-10 15:46:42 -0700 | [diff] [blame] | 216 | |
Craig Tiller | b5dcec5 | 2015-01-13 11:13:42 -0800 | [diff] [blame] | 217 | grpc_init_call(TSRMLS_C); |
Stanley Cheung | 5b3dc4a | 2017-08-03 18:00:25 -0700 | [diff] [blame] | 218 | GRPC_STARTUP(channel); |
Craig Tiller | b5dcec5 | 2015-01-13 11:13:42 -0800 | [diff] [blame] | 219 | grpc_init_server(TSRMLS_C); |
Craig Tiller | b5dcec5 | 2015-01-13 11:13:42 -0800 | [diff] [blame] | 220 | grpc_init_timeval(TSRMLS_C); |
Stanley Cheung | aeea102 | 2015-10-21 17:00:49 -0700 | [diff] [blame] | 221 | grpc_init_channel_credentials(TSRMLS_C); |
| 222 | grpc_init_call_credentials(TSRMLS_C); |
Craig Tiller | b5dcec5 | 2015-01-13 11:13:42 -0800 | [diff] [blame] | 223 | grpc_init_server_credentials(TSRMLS_C); |
| 224 | return SUCCESS; |
mlumish | b892a27 | 2014-12-09 16:28:23 -0800 | [diff] [blame] | 225 | } |
| 226 | /* }}} */ |
| 227 | |
| 228 | /* {{{ PHP_MSHUTDOWN_FUNCTION |
| 229 | */ |
Craig Tiller | b5dcec5 | 2015-01-13 11:13:42 -0800 | [diff] [blame] | 230 | PHP_MSHUTDOWN_FUNCTION(grpc) { |
| 231 | /* uncomment this line if you have INI entries |
thinkerou | a3730b7 | 2016-07-20 16:59:54 +0800 | [diff] [blame] | 232 | UNREGISTER_INI_ENTRIES(); |
Craig Tiller | b5dcec5 | 2015-01-13 11:13:42 -0800 | [diff] [blame] | 233 | */ |
Stanley Cheung | 8b24908 | 2016-06-29 15:13:06 -0700 | [diff] [blame] | 234 | // WARNING: This function IS being called by PHP when the extension |
| 235 | // is unloaded but the logs were somehow suppressed. |
Stanley Cheung | 5d55948 | 2017-08-22 13:15:01 -0700 | [diff] [blame] | 236 | if (GRPC_G(initialized)) { |
ZhouyihaiDing | 5c77035 | 2018-04-09 13:20:31 -0700 | [diff] [blame] | 237 | zend_hash_clean(&grpc_persistent_list); |
| 238 | zend_hash_destroy(&grpc_persistent_list); |
ZhouyihaiDing | 9ef881e | 2018-04-12 16:43:33 -0700 | [diff] [blame] | 239 | zend_hash_clean(&grpc_target_upper_bound_map); |
| 240 | zend_hash_destroy(&grpc_target_upper_bound_map); |
Stanley Cheung | 5d55948 | 2017-08-22 13:15:01 -0700 | [diff] [blame] | 241 | grpc_shutdown_timeval(TSRMLS_C); |
| 242 | grpc_php_shutdown_completion_queue(TSRMLS_C); |
| 243 | grpc_shutdown(); |
| 244 | GRPC_G(initialized) = 0; |
| 245 | } |
Craig Tiller | b5dcec5 | 2015-01-13 11:13:42 -0800 | [diff] [blame] | 246 | return SUCCESS; |
mlumish | b892a27 | 2014-12-09 16:28:23 -0800 | [diff] [blame] | 247 | } |
| 248 | /* }}} */ |
| 249 | |
| 250 | /* {{{ PHP_MINFO_FUNCTION |
| 251 | */ |
Craig Tiller | b5dcec5 | 2015-01-13 11:13:42 -0800 | [diff] [blame] | 252 | PHP_MINFO_FUNCTION(grpc) { |
| 253 | php_info_print_table_start(); |
ZhouyihaiDing | e2af6d9 | 2017-12-08 09:49:55 -0800 | [diff] [blame] | 254 | php_info_print_table_row(2, "grpc support", "enabled"); |
| 255 | php_info_print_table_row(2, "grpc module version", PHP_GRPC_VERSION); |
Craig Tiller | b5dcec5 | 2015-01-13 11:13:42 -0800 | [diff] [blame] | 256 | php_info_print_table_end(); |
Craig Tiller | b5dcec5 | 2015-01-13 11:13:42 -0800 | [diff] [blame] | 257 | /* Remove comments if you have entries in php.ini |
thinkerou | a3730b7 | 2016-07-20 16:59:54 +0800 | [diff] [blame] | 258 | DISPLAY_INI_ENTRIES(); |
Craig Tiller | b5dcec5 | 2015-01-13 11:13:42 -0800 | [diff] [blame] | 259 | */ |
mlumish | b892a27 | 2014-12-09 16:28:23 -0800 | [diff] [blame] | 260 | } |
| 261 | /* }}} */ |
Stanley Cheung | 5d55948 | 2017-08-22 13:15:01 -0700 | [diff] [blame] | 262 | |
| 263 | /* {{{ PHP_RINIT_FUNCTION |
| 264 | */ |
| 265 | PHP_RINIT_FUNCTION(grpc) { |
| 266 | if (!GRPC_G(initialized)) { |
| 267 | grpc_init(); |
| 268 | grpc_php_init_completion_queue(TSRMLS_C); |
| 269 | GRPC_G(initialized) = 1; |
| 270 | } |
| 271 | return SUCCESS; |
| 272 | } |
| 273 | /* }}} */ |
| 274 | |
| 275 | /* {{{ PHP_GINIT_FUNCTION |
| 276 | */ |
| 277 | static PHP_GINIT_FUNCTION(grpc) { |
| 278 | grpc_globals->initialized = 0; |
| 279 | } |
| 280 | /* }}} */ |
| 281 | |
mlumish | b892a27 | 2014-12-09 16:28:23 -0800 | [diff] [blame] | 282 | /* The previous line is meant for vim and emacs, so it can correctly fold and |
| 283 | unfold functions in source code. See the corresponding marks just before |
| 284 | function definition, where the functions purpose is also documented. Please |
| 285 | follow this convention for the convenience of others editing your code. |
| 286 | */ |