-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgrpc.php
724 lines (640 loc) · 22.3 KB
/
grpc.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
<?php
/**
* Helper autocomplete for php grpc extension
* @author Dmitry Gavriloff <[email protected]>
* @link https://github.com/iMega/grpc-phpdoc
*/
/**
* Grpc
* @see https://github.com/grpc/grpc/tree/master/src/php/ext/grpc
*/
namespace Grpc
{
/**
* Register call error constants
*/
/**
* everything went ok
*/
const CALL_OK = 0;
/**
* something failed, we don't know what
*/
const CALL_ERROR = 1;
/**
* this method is not available on the server
*/
const CALL_ERROR_NOT_ON_SERVER = 2;
/**
* this method is not available on the client
*/
const CALL_ERROR_NOT_ON_CLIENT = 3;
/**
* this method must be called before server_accept
*/
const CALL_ERROR_ALREADY_ACCEPTED = 4;
/**
* this method must be called before invoke
*/
const CALL_ERROR_ALREADY_INVOKED = 5;
/**
* this method must be called after invoke
*/
const CALL_ERROR_NOT_INVOKED = 6;
/**
* this call is already finished
* (writes_done or write_status has already been called)
*/
const CALL_ERROR_ALREADY_FINISHED = 7;
/**
* there is already an outstanding read/write operation on the call
*/
const CALL_ERROR_TOO_MANY_OPERATIONS = 8;
/**
* the flags value was illegal for this call
*/
const CALL_ERROR_INVALID_FLAGS = 9;
/**
* invalid metadata was passed to this call
*/
const CALL_ERROR_INVALID_METADATA = 10;
/**
* invalid message was passed to this call
*/
const CALL_ERROR_INVALID_MESSAGE = 11;
/**
* completion queue for notification has not been registered with the
* server
*/
const CALL_ERROR_NOT_SERVER_COMPLETION_QUEUE = 12;
/**
* this batch of operations leads to more operations than allowed
*/
const CALL_ERROR_BATCH_TOO_BIG = 13;
/**
* payload type requested is not the type registered
*/
const CALL_ERROR_PAYLOAD_TYPE_MISMATCH = 14;
/**
* Register write flags
*/
/**
* Hint that the write may be buffered and need not go out on the wire
* immediately. GRPC is free to buffer the message until the next non-buffered
* write, or until writes_done, but it need not buffer completely or at all.
*/
const WRITE_BUFFER_HINT = 1;
/**
* Force compression to be disabled for a particular write
* (start_write/add_metadata). Illegal on invoke/accept.
*/
const WRITE_NO_COMPRESS = 2;
/**
* Register status constants
*/
/**
* Not an error; returned on success
*/
const STATUS_OK = 0;
/**
* The operation was cancelled (typically by the caller).
*/
const STATUS_CANCELLED = 1;
/**
* Unknown error. An example of where this error may be returned is
* if a Status value received from another address space belongs to
* an error-space that is not known in this address space. Also
* errors raised by APIs that do not return enough error information
* may be converted to this error.
*/
const STATUS_UNKNOWN = 2;
/**
* Client specified an invalid argument. Note that this differs
* from FAILED_PRECONDITION. INVALID_ARGUMENT indicates arguments
* that are problematic regardless of the state of the system
* (e.g., a malformed file name).
*/
const STATUS_INVALID_ARGUMENT = 3;
/**
* Deadline expired before operation could complete. For operations
* that change the state of the system, this error may be returned
* even if the operation has completed successfully. For example, a
* successful response from a server could have been delayed long
* enough for the deadline to expire.
*/
const STATUS_DEADLINE_EXCEEDED = 4;
/**
* Some requested entity (e.g., file or directory) was not found.
*/
const STATUS_NOT_FOUND = 5;
/* Some entity that we attempted to create (e.g., file or directory)
* already exists.
*/
const STATUS_ALREADY_EXISTS = 6;
/**
* The caller does not have permission to execute the specified
* operation. PERMISSION_DENIED must not be used for rejections
* caused by exhausting some resource (use RESOURCE_EXHAUSTED
* instead for those errors). PERMISSION_DENIED must not be
* used if the caller can not be identified (use UNAUTHENTICATED
* instead for those errors).
*/
const STATUS_PERMISSION_DENIED = 7;
/**
* The request does not have valid authentication credentials for the
* operation.
*/
const STATUS_UNAUTHENTICATED = 16;
/**
* Some resource has been exhausted, perhaps a per-user quota, or
* perhaps the entire file system is out of space.
*/
const STATUS_RESOURCE_EXHAUSTED = 8;
/**
* Operation was rejected because the system is not in a state
* required for the operation's execution. For example, directory
* to be deleted may be non-empty, an rmdir operation is applied to
* a non-directory, etc.
*
* A litmus test that may help a service implementor in deciding
* between FAILED_PRECONDITION, ABORTED, and UNAVAILABLE:
* (a) Use UNAVAILABLE if the client can retry just the failing call.
* (b) Use ABORTED if the client should retry at a higher-level
* (e.g., restarting a read-modify-write sequence).
* (c) Use FAILED_PRECONDITION if the client should not retry until
* the system state has been explicitly fixed. E.g., if an "rmdir"
* fails because the directory is non-empty, FAILED_PRECONDITION
* should be returned since the client should not retry unless
* they have first fixed up the directory by deleting files from it.
* (d) Use FAILED_PRECONDITION if the client performs conditional
* REST Get/Update/Delete on a resource and the resource on the
* server does not match the condition. E.g., conflicting
* read-modify-write on the same resource.
*/
const STATUS_FAILED_PRECONDITION = 9;
/**
* The operation was aborted, typically due to a concurrency issue
* like sequencer check failures, transaction aborts, etc.
*
* See litmus test above for deciding between FAILED_PRECONDITION,
* ABORTED, and UNAVAILABLE.
*/
const STATUS_ABORTED = 10;
/**
* Operation was attempted past the valid range. E.g., seeking or
* reading past end of file.
*
* Unlike INVALID_ARGUMENT, this error indicates a problem that may
* be fixed if the system state changes. For example, a 32-bit file
* system will generate INVALID_ARGUMENT if asked to read at an
* offset that is not in the range [0,2^32-1], but it will generate
* OUT_OF_RANGE if asked to read from an offset past the current
* file size.
*
* There is a fair bit of overlap between FAILED_PRECONDITION and
* OUT_OF_RANGE. We recommend using OUT_OF_RANGE (the more specific
* error) when it applies so that callers who are iterating through
* a space can easily look for an OUT_OF_RANGE error to detect when
* they are done.
*/
const STATUS_OUT_OF_RANGE = 11;
/**
* Operation is not implemented or not supported/enabled in this service.
*/
const STATUS_UNIMPLEMENTED = 12;
/**
* Internal errors. Means some invariants expected by underlying
* system has been broken. If you see one of these errors,
* something is very broken.
*/
const STATUS_INTERNAL = 13;
/**
* The service is currently unavailable. This is a most likely a
* transient condition and may be corrected by retrying with
* a backoff.
*
* See litmus test above for deciding between FAILED_PRECONDITION,
* ABORTED, and UNAVAILABLE.
*/
const STATUS_UNAVAILABLE = 14;
/**
* Unrecoverable data loss or corruption.
*/
const STATUS_DATA_LOSS = 15;
/**
* Register op type constants
*/
/**
* Send initial metadata: one and only one instance MUST be sent for each
* call, unless the call was cancelled - in which case this can be skipped.
* This op completes after all bytes of metadata have been accepted by
* outgoing flow control.
*/
const OP_SEND_INITIAL_METADATA = 0;
/**
* Send a message: 0 or more of these operations can occur for each call.
* This op completes after all bytes for the message have been accepted by
* outgoing flow control.
*/
const OP_SEND_MESSAGE = 1;
/** Send a close from the client: one and only one instance MUST be sent from
* the client, unless the call was cancelled - in which case this can be
* skipped.
* This op completes after all bytes for the call (including the close)
* have passed outgoing flow control.
*/
const OP_SEND_CLOSE_FROM_CLIENT = 2;
/**
* Send status from the server: one and only one instance MUST be sent from
* the server unless the call was cancelled - in which case this can be
* skipped.
* This op completes after all bytes for the call (including the status)
* have passed outgoing flow control.
*/
const OP_SEND_STATUS_FROM_SERVER = 3;
/**
* Receive initial metadata: one and only one MUST be made on the client,
* must not be made on the server.
* This op completes after all initial metadata has been read from the
* peer.
*/
const OP_RECV_INITIAL_METADATA = 4;
/**
* Receive a message: 0 or more of these operations can occur for each call.
* This op completes after all bytes of the received message have been
* read, or after a half-close has been received on this call.
*/
const OP_RECV_MESSAGE = 5;
/**
* Receive status on the client: one and only one must be made on the client.
* This operation always succeeds, meaning ops paired with this operation
* will also appear to succeed, even though they may not have. In that case
* the status will indicate some failure.
* This op completes after all activity on the call has completed.
*/
const OP_RECV_STATUS_ON_CLIENT = 6;
/**
* Receive close on the server: one and only one must be made on the
* server.
* This op completes after the close has been received by the server.
* This operation always succeeds, meaning ops paired with this operation
* will also appear to succeed, even though they may not have.
*/
const OP_RECV_CLOSE_ON_SERVER = 7;
/**
* Register connectivity state constants
*/
/**
* channel is idle
*/
const CHANNEL_IDLE = 0;
/**
* channel is connecting
*/
const CHANNEL_CONNECTING = 1;
/**
* channel is ready for work
*/
const CHANNEL_READY = 2;
/**
* channel has seen a failure but expects to recover
*/
const CHANNEL_TRANSIENT_FAILURE = 3;
/**
* channel has seen a failure that it cannot recover from
*/
const CHANNEL_SHUTDOWN = 4;
const CHANNEL_FATAL_FAILURE = 4;
/**
* Class Server
* @see https://github.com/grpc/grpc/tree/master/src/php/ext/grpc
*/
class Server
{
/**
* Constructs a new instance of the Server class
*
* @param array $args The arguments to pass to the server (optional)
*/
public function __construct(array $args) {}
/**
* Request a call on a server. Creates a single GRPC_SERVER_RPC_NEW event.
*
* @param int $tag_new The tag to associate with the new request
* @param int $tag_cancel The tag to use if the call is cancelled
*/
public function requestCall($tag_new, $tag_cancel) {}
/**
* Add a http2 over tcp listener.
*
* @param string $addr The address to add
*
* @return bool true on success, false on failure
*/
public function addHttp2Port($addr) {}
/**
* Add a secure http2 over tcp listener.
*
* @param string $addr The address to add
* @param ServerCredentials $creds_obj
*
* @return bool true on success, false on failure
*/
public function addSecureHttp2Port($addr, $creds_obj) {}
/**
* Start a server - tells all listeners to start listening
*/
public function start() {}
}
/**
* Class ServerCredentials
* @see https://github.com/grpc/grpc/tree/master/src/php/ext/grpc
*/
class ServerCredentials
{
/**
* Create SSL credentials.
*
* @param string $pem_root_certs PEM encoding of the server root certificates
* @param string $pem_private_key PEM encoding of the client's private key
* @param string $pem_cert_chain PEM encoding of the client's certificate chain
*
* @return object Credentials The new SSL credentials object
* @throws \InvalidArgumentException
*/
public static function createSsl(
$pem_root_certs,
$pem_private_key,
$pem_cert_chain
) {}
}
/**
* Class Channel
* @see https://github.com/grpc/grpc/tree/master/src/php/ext/grpc
*/
class Channel
{
/**
* Construct an instance of the Channel class. If the $args array contains a
* "credentials" key mapping to a ChannelCredentials object, a secure channel
* will be created with those credentials.
*
* @param string $target The hostname to associate with this channel
* @param array $args The arguments to pass to the Channel (optional)
*
* @throws \InvalidArgumentException
*/
public function __construct($target, $args = array()) {}
/**
* Get the endpoint this call/stream is connected to
*
* @return string The URI of the endpoint
*/
public function getTarget() {}
/**
* Get the connectivity state of the channel
*
* @param bool $try_to_connect try to connect on the channel
*
* @return int The grpc connectivity state
* @throws \InvalidArgumentException
*/
public function getConnectivityState($try_to_connect = false) {}
/**
* Watch the connectivity state of the channel until it changed
*
* @param int $last_state The previous connectivity state of the channel
* @param Timeval $deadline_obj The deadline this function should wait until
*
* @return bool If the connectivity state changes from last_state
* before deadline
* @throws \InvalidArgumentException
*/
public function watchConnectivityState($last_state, Timeval $deadline_obj) {}
/**
* Close the channel
*/
public function close() {}
}
/**
* Class ChannelCredentials
* @see https://github.com/grpc/grpc/tree/master/src/php/ext/grpc
*/
class ChannelCredentials
{
/**
* Set default roots pem.
*
* @param string $pem_roots PEM encoding of the server root certificates
*
* @throws \InvalidArgumentException
*/
public static function setDefaultRootsPem($pem_roots) {}
/**
* Create a default channel credentials object.
*
* @return ChannelCredentials The new default channel credentials object
*/
public static function createDefault() {}
/**
* Create SSL credentials.
*
* @param string $pem_root_certs PEM encoding of the server root certificates
* @param string $pem_private_key PEM encoding of the client's private key
* @param string $pem_cert_chain PEM encoding of the client's certificate chain
*
* @return ChannelCredentials The new SSL credentials object
* @throws \InvalidArgumentException
*/
public static function createSsl(
$pem_root_certs,
$pem_private_key = '',
$pem_cert_chain = ''
) {}
/**
* Create composite credentials from two existing credentials.
*
* @param ChannelCredentials $cred1 The first credential
* @param CallCredentials $cred2 The second credential
*
* @return ChannelCredentials The new composite credentials object
* @throws \InvalidArgumentException
*/
public static function createComposite(
ChannelCredentials $cred1,
CallCredentials $cred2
) {}
/**
* Create insecure channel credentials
*
* @return null
*/
public static function createInsecure() {}
}
/**
* Class Call
* @see https://github.com/grpc/grpc/tree/master/src/php/ext/grpc
*/
class Call
{
/**
* Constructs a new instance of the Call class.
*
* @param Channel $channel The channel to associate the call with.
* Must not be closed.
* @param string $method The method to call
* @param Timeval $absolute_deadline The deadline for completing the call
*
* @throws \InvalidArgumentException
*/
public function __construct(
Channel $channel,
$method,
Timeval $absolute_deadline,
$host_override = null
) {}
/**
* Start a batch of RPC actions.
*
* @param array $batch Array of actions to take
*
* @return object Object with results of all actions
* @throws \InvalidArgumentException
* @throws \LogicException
*/
public function startBatch(array $batch) {}
/**
* Set the CallCredentials for this call.
*
* @param CallCredentials $creds_obj The CallCredentials object
*
* @return int The error code
* @throws \InvalidArgumentException
*/
public function setCredentials(CallCredentials $creds_obj) {}
/**
* Get the endpoint this call/stream is connected to
*
* @return string The URI of the endpoint
*/
public function getPeer() {}
/**
* Cancel the call. This will cause the call to end with STATUS_CANCELLED if it
* has not already ended with another status.
*/
public function cancel() {}
}
/**
* Class CallCredentials
* @see https://github.com/grpc/grpc/tree/master/src/php/ext/grpc
*/
class CallCredentials
{
/**
* Create composite credentials from two existing credentials.
*
* @param CallCredentials $cred1 The first credential
* @param CallCredentials $cred2 The second credential
*
* @return CallCredentials The new composite credentials object
* @throws \InvalidArgumentException
*/
public static function createComposite(
CallCredentials $cred1,
CallCredentials $cred2
) {}
/**
* Create a call credentials object from the plugin API
*
* @param \Closure $callback The callback function
*
* @return CallCredentials The new call credentials object
* @throws \InvalidArgumentException
*/
public static function createFromPlugin(\Closure $callback) {}
}
/**
* Class Timeval
*
* @see https://github.com/grpc/grpc/tree/master/src/php/ext/grpc
*/
class Timeval
{
/**
* Constructs a new instance of the Timeval class
*
* @param int $usec The number of microseconds in the interval
*/
public function __construct($usec) {}
/**
* Adds another Timeval to this one and returns the sum. Calculations saturate
* at infinities.
*
* @param Timeval $other The other Timeval object to add
*
* @return Timeval A new Timeval object containing the sum
* @throws \InvalidArgumentException
*/
public function add(Timeval $other) {}
/**
* Return negative, 0, or positive according to whether a < b, a == b, or a > b
* respectively.
*
* @param Timeval $a The first time to compare
* @param Timeval $b The second time to compare
*
* @return int
* @throws \InvalidArgumentException
*/
public static function compare(Timeval $a, Timeval $b) {}
/**
* Returns the infinite future time value as a timeval object
*
* @return Timeval Infinite future time value
*/
public static function infFuture() {}
/**
* Returns the infinite past time value as a timeval object
*
* @return Timeval Infinite past time value
*/
public static function infPast() {}
/**
* Returns the current time as a timeval object
*
* @return Timeval The current time
*/
public static function now() {}
/**
* Checks whether the two times are within $threshold of each other
*
* @param Timeval $a The first time to compare
* @param Timeval $b The second time to compare
* @param Timeval $threshold The threshold to check against
*
* @return bool True if $a and $b are within $threshold, False otherwise
* @throws \InvalidArgumentException
*/
public static function similar(Timeval $a, Timeval $b, Timeval $threshold) {}
/**
* Sleep until this time, interpreted as an absolute timeout
*/
public function sleepUntil() {}
/**
* Subtracts another Timeval from this one and returns the difference.
* Calculations saturate at infinities.
*
* @param Timeval $other The other Timeval object to subtract
*
* @return Timeval A new Timeval object containing the sum
* @throws \InvalidArgumentException
*/
public function subtract(Timeval $other) {}
/**
* Returns the zero time interval as a timeval object
*
* @return Timeval Zero length time interval
*/
public static function zero() {}
}
}