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