forked from swoole/swoole-src
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathphp_swoole_library.h
1876 lines (1864 loc) Β· 63.4 KB
/
php_swoole_library.h
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
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* Generated by build-library.php, Please DO NOT modify!
*/
static const char* swoole_library_source_constants =
"\n"
"define('SWOOLE_LIBRARY', true);\n";
static const char* swoole_library_source_std_array =
"\n"
"function swoole_array_walk(array &$array, callable $callback, ...$userdata): bool\n"
"{\n"
" if (($argc = func_num_args()) > 3) {\n"
" throw new TypeError(\"array_walk() expects at most 3 parameters, {$argc} given\");\n"
" }\n"
" foreach ($array as $key => &$item) {\n"
" $callback($item, $key, ...$userdata);\n"
" }\n"
" return true;\n"
"}\n"
"\n"
"function swoole_array_walk_recursive(array &$array, callable $callback, ...$userdata): bool\n"
"{\n"
" if (($argc = func_num_args()) > 3) {\n"
" throw new TypeError(\"array_walk_recursive() expects at most 3 parameters, {$argc} given\");\n"
" }\n"
" foreach ($array as $key => &$item) {\n"
" if (is_array($item)) {\n"
" swoole_array_walk_recursive($item, $callback, ...$userdata);\n"
" } else {\n"
" $callback($item, $key, ...$userdata);\n"
" }\n"
" }\n"
" return true;\n"
"}\n";
static const char* swoole_library_source_ext_curl =
"\n"
"\n"
"class swoole_curl_handler\n"
"{\n"
" private const ERRORS = [\n"
" CURLE_URL_MALFORMAT => 'No URL set!',\n"
" ];\n"
"\n"
" /** @var Swoole\\Coroutine\\Http\\Client */\n"
" private $client;\n"
" private $info = [\n"
" 'url' => '',\n"
" 'content_type' => '',\n"
" 'http_code' => 0,\n"
" 'header_size' => 0,\n"
" 'request_size' => 0,\n"
" 'filetime' => -1,\n"
" 'ssl_verify_result' => 0,\n"
" 'redirect_count' => 0,\n"
" 'total_time' => 5.3E-5,\n"
" 'namelookup_time' => 0.0,\n"
" 'connect_time' => 0.0,\n"
" 'pretransfer_time' => 0.0,\n"
" 'size_upload' => 0.0,\n"
" 'size_download' => 0.0,\n"
" 'speed_download' => 0.0,\n"
" 'speed_upload' => 0.0,\n"
" 'download_content_length' => -1.0,\n"
" 'upload_content_length' => -1.0,\n"
" 'starttransfer_time' => 0.0,\n"
" 'redirect_time' => 0.0,\n"
" 'redirect_url' => '',\n"
" 'primary_ip' => '',\n"
" 'certinfo' => [],\n"
" 'primary_port' => 0,\n"
" 'local_ip' => '',\n"
" 'local_port' => 0,\n"
" 'http_version' => 0,\n"
" 'protocol' => 0,\n"
" 'ssl_verifyresult' => 0,\n"
" 'scheme' => '',\n"
" ];\n"
" private $urlInfo;\n"
" private $postData;\n"
" private $outputStream;\n"
" private $proxy;\n"
" private $clientOptions = [];\n"
" private $followLocation = false;\n"
" private $maxRedirs;\n"
"\n"
" /** @var callable */\n"
" private $headerFunction;\n"
" /** @var callable */\n"
" private $readFunction;\n"
" /** @var callable */\n"
" private $writeFunction;\n"
" /** @var callable */\n"
" private $progressFunction;\n"
"\n"
" public $returnTransfer = false;\n"
" public $method = 'GET';\n"
" public $headers = [];\n"
"\n"
" public $errCode = 0;\n"
" public $errMsg = '';\n"
"\n"
" public function __construct($url = null)\n"
" {\n"
" if ($url) {\n"
" $this->create($url);\n"
" }\n"
" }\n"
"\n"
" private function create(string $url): void\n"
" {\n"
" if (!swoole_string($url)->contains('://')) {\n"
" $url = 'http://' . $url;\n"
" }\n"
" $this->info['url'] = $url;\n"
" $info = parse_url($url);\n"
" $proto = swoole_array_default_value($info, 'scheme');\n"
" if ($proto != 'http' and $proto != 'https') {\n"
" $this->setError(CURLE_UNSUPPORTED_PROTOCOL, \"Protocol \\\"{$proto}\\\" not supported or disabled in libcurl\");\n"
" return;\n"
" }\n"
" $ssl = $proto === 'https';\n"
" if (empty($info['port'])) {\n"
" $port = $ssl ? 443 : 80;\n"
" } else {\n"
" $port = intval($info['port']);\n"
" }\n"
" $this->urlInfo = $info;\n"
" $this->client = new Swoole\\Coroutine\\Http\\Client($info['host'], $port, $ssl);\n"
" }\n"
"\n"
" public function execute()\n"
" {\n"
" $this->info['redirect_count'] = $this->info['starttransfer_time'] = 0;\n"
" $this->info['redirect_url'] = '';\n"
" $timeBegin = microtime(true);\n"
" /**\n"
" * Socket\n"
" */\n"
" $client = $this->client;\n"
" if (!$client) {\n"
" if (!$this->errCode) {\n"
" $this->setError(CURLE_URL_MALFORMAT);\n"
" }\n"
" return false;\n"
" }\n"
" $isRedirect = false;\n"
" do {\n"
" if ($isRedirect and !$client) {\n"
" $proto = swoole_array_default_value($this->urlInfo, 'scheme');\n"
" if ($proto != 'http' and $proto != 'https') {\n"
" $this->setError(CURLE_UNSUPPORTED_PROTOCOL, \"Protocol \\\"{$proto}\\\" not supported or disabled in libcurl\");\n"
" return;\n"
" }\n"
" $ssl = $proto === 'https';\n"
" if (empty($this->urlInfo['port'])) {\n"
" $port = $ssl ? 443 : 80;\n"
" } else {\n"
" $port = intval($this->urlInfo['port']);\n"
" }\n"
" $client = new Swoole\\Coroutine\\Http\\Client($this->urlInfo['host'], $port, $ssl);\n"
" }\n"
" /**\n"
" * Http Proxy\n"
" */\n"
" if ($this->proxy) {\n"
" list($proxy_host, $proxy_port) = explode(':', $this->proxy);\n"
" if (!filter_var($proxy_host, FILTER_VALIDATE_IP)) {\n"
" $ip = \\Swoole\\Coroutine::gethostbyname($proxy_host);\n"
" if (!$ip) {\n"
" $this->setError(CURLE_COULDNT_RESOLVE_PROXY, 'Could not resolve proxy: ' . $proxy_host);\n"
" return false;\n"
" } else {\n"
" $proxy_host = $ip;\n"
" }\n"
" }\n"
" $client->set(['http_proxy_host' => $proxy_host, 'http_proxy_port' => $proxy_port]);\n"
" }\n"
" /**\n"
" * Client Options\n"
" */\n"
" if ($this->clientOptions) {\n"
" $client->set($this->clientOptions);\n"
" }\n"
" $client->setMethod($this->method);\n"
" /**\n"
" * Upload File\n"
" */\n"
" if ($this->postData and is_array($this->postData)) {\n"
" foreach ($this->postData as $k => $v) {\n"
" if ($v instanceof CURLFile) {\n"
" $client->addFile($v->getFilename(), $k, $v->getMimeType() ?: 'application/octet-stream', $v->getPostFilename());\n"
" unset($this->postData[$k]);\n"
" }\n"
" }\n"
" }\n"
" /**\n"
" * Post Data\n"
" */\n"
" if ($this->postData) {\n"
" if (is_string($this->postData) and empty($this->headers['Content-Type'])) {\n"
" $this->headers['Content-Type'] = 'application/x-www-form-urlencoded';\n"
" }\n"
" $client->setData($this->postData);\n"
" $this->postData = [];\n"
" }\n"
" /**\n"
" * Http Header\n"
" */\n"
" if ($this->headers) {\n"
" $client->setHeaders($this->headers);\n"
" }\n"
" /**\n"
" * Execute\n"
" */\n"
" $executeResult = $client->execute($this->getUrl());\n"
" if (!$executeResult) {\n"
" $errCode = $client->errCode;\n"
" if ($errCode == 1 and $client->errMsg == 'Unknown host') {\n"
" $this->setError(CURLE_COULDNT_RESOLVE_HOST, 'Could not resolve host: ' . $client->host);\n"
" }\n"
" $this->info['total_time'] = microtime(true) - $timeBegin;\n"
" return false;\n"
" }\n"
" if ($client->statusCode >= 300 and $client->statusCode < 400 and isset($client->headers['location'])) {\n"
" $redirectParsedUrl = $this->getRedirectUrl($client->headers['location']);\n"
" $redirectUrl = $this->unparseUrl($redirectParsedUrl);\n"
" if ($this->followLocation and (null === $this->maxRedirs or $this->info['redirect_count'] < $this->maxRedirs)) {\n"
" $isRedirect = true;\n"
" if (0 === $this->info['redirect_count']) {\n"
" $this->info['starttransfer_time'] = microtime(true) - $timeBegin;\n"
" $redirectBeginTime = microtime(true);\n"
" }\n"
" // force GET\n"
" if (in_array($client->statusCode, [301, 302, 303])) {\n"
" $this->method = 'GET';\n"
" }\n"
" if ($this->urlInfo['host'] !== $redirectParsedUrl['host'] or ($this->urlInfo['port'] ?? null) !== ($redirectParsedUrl['port'] ?? null) or $this->urlInfo['scheme'] !== $redirectParsedUrl['scheme']) {\n"
" // If host, port, and scheme are the same, reuse $client. Otherwise, release the old $client\n"
" $client = null;\n"
" }\n"
" $this->urlInfo = $redirectParsedUrl;\n"
" $this->info['url'] = $redirectUrl;\n"
" $this->info['redirect_count']++;\n"
" } else {\n"
" $this->info['redirect_url'] = $redirectUrl;\n"
" break;\n"
" }\n"
" } else {\n"
" break;\n"
" }\n"
" } while (true);\n"
" $this->info['total_time'] = microtime(true) - $timeBegin;\n"
" $this->info['http_code'] = $client->statusCode;\n"
" $this->info['content_type'] = $client->headers['content-type'] ?? '';\n"
" $this->info['size_download'] = $this->info['download_content_length'] = strlen($client->body);;\n"
" $this->info['speed_download'] = 1 / $this->info['total_time'] * $this->info['size_download'];\n"
" if (isset($redirectBeginTime)) {\n"
" $this->info['redirect_time'] = microtime(true) - $redirectBeginTime;\n"
" }\n"
"\n"
" if ($client->headers and $this->headerFunction) {\n"
" $cb = $this->headerFunction;\n"
" if ($client->statusCode === 200) {\n"
" $cb($this, \"HTTP/1.1 200 OK\\r\\n\");\n"
" }\n"
" foreach ($client->headers as $k => $v) {\n"
" $cb($this, \"$k: $v\\r\\n\");\n"
" }\n"
" $cb($this, '');\n"
" }\n"
"\n"
" if ($client->body and $this->readFunction) {\n"
" $cb = $this->readFunction;\n"
" $cb($this, $this->outputStream, strlen($client->body));\n"
" }\n"
" if ($this->returnTransfer) {\n"
" return $client->body;\n"
" } else {\n"
" if ($this->outputStream) {\n"
" return fwrite($this->outputStream, $client->body) === strlen($client->body);\n"
" } else {\n"
" echo $client->body;\n"
" }\n"
" return true;\n"
" }\n"
" }\n"
"\n"
" public function close(): void\n"
" {\n"
" $this->client = null;\n"
" }\n"
"\n"
" private function setError($code, $msg = ''): void\n"
" {\n"
" $this->errCode = $code;\n"
" $this->errMsg = $msg ? $msg : self::ERRORS[$code];\n"
" }\n"
"\n"
" private function getUrl(): string\n"
" {\n"
" if (empty($this->urlInfo['path'])) {\n"
" $url = '/';\n"
" } else {\n"
" $url = $this->urlInfo['path'];\n"
" }\n"
" if (!empty($this->urlInfo['query'])) {\n"
" $url .= '?' . $this->urlInfo['query'];\n"
" }\n"
" if (!empty($this->urlInfo['fragment'])) {\n"
" $url .= '#' . $this->urlInfo['fragment'];\n"
" }\n"
" return $url;\n"
" }\n"
"\n"
" /**\n"
" * @param int $opt\n"
" * @param $value\n"
" * @return bool\n"
" * @throws swoole_curl_exception\n"
" */\n"
" public function setOption(int $opt, $value): bool\n"
" {\n"
" switch ($opt) {\n"
" /**\n"
" * Basic\n"
" */\n"
" case CURLOPT_URL:\n"
" $this->create($value);\n"
" break;\n"
" case CURLOPT_RETURNTRANSFER:\n"
" $this->returnTransfer = $value;\n"
" break;\n"
" case CURLOPT_ENCODING:\n"
" if (empty($value)) {\n"
" $value = 'gzip';\n"
" }\n"
" $this->headers['Accept-Encoding'] = $value;\n"
" break;\n"
" case CURLOPT_PROXY:\n"
" $this->proxy = $value;\n"
" break;\n"
" /**\n"
" * Http Post\n"
" */\n"
" case CURLOPT_POST:\n"
" $this->method = 'POST';\n"
" break;\n"
" case CURLOPT_POSTFIELDS:\n"
" $this->postData = $value;\n"
" $this->method = 'POST';\n"
" break;\n"
" /**\n"
" * Upload\n"
" */\n"
" case CURLOPT_SAFE_UPLOAD:\n"
" if (!$value) {\n"
" trigger_error('curl_setopt(): Disabling safe uploads is no longer supported', E_USER_WARNING);\n"
" }\n"
" break;\n"
" /**\n"
" * Http Header\n"
" */\n"
" case CURLOPT_HTTPHEADER:\n"
" if (!is_array($value) and !($value instanceof Iterator)) {\n"
" trigger_error('swoole_curl_setopt(): You must pass either an object or an array with the CURLOPT_HTTPHEADER argument', E_USER_WARNING);\n"
" return false;\n"
" }\n"
" foreach ($value as $header) {\n"
" list($k, $v) = explode(':', $header);\n"
" $v = trim($v);\n"
" if ($v) {\n"
" $this->headers[$k] = $v;\n"
" }\n"
" }\n"
" break;\n"
" case CURLOPT_REFERER:\n"
" $this->headers['Referer'] = $value;\n"
" break;\n"
"\n"
" case CURLOPT_USERAGENT:\n"
" $this->headers['User-Agent'] = $value;\n"
" break;\n"
"\n"
" case CURLOPT_CUSTOMREQUEST:\n"
" break;\n"
" case CURLOPT_PROTOCOLS:\n"
" if ($value > 3) {\n"
" throw new swoole_curl_exception(\"option[{$opt}={$value}] not supported\");\n"
" }\n"
" break;\n"
" case CURLOPT_HTTP_VERSION:\n"
" if ($value != CURL_HTTP_VERSION_1_1) {\n"
" trigger_error(\"swoole_curl: http version[{$value}] not supported\", E_USER_WARNING);\n"
" }\n"
" break;\n"
" /**\n"
" * Http Cookie\n"
" */\n"
" case CURLOPT_COOKIE:\n"
" $this->headers['Cookie'] = $value;\n"
" break;\n"
" case CURLOPT_SSL_VERIFYHOST:\n"
" break;\n"
" case CURLOPT_SSL_VERIFYPEER:\n"
" $this->clientOptions['ssl_verify_peer'] = $value;\n"
" break;\n"
" case CURLOPT_CONNECTTIMEOUT:\n"
" $this->clientOptions['connect_timeout'] = $value;\n"
" break;\n"
" case CURLOPT_CONNECTTIMEOUT_MS:\n"
" $this->clientOptions['connect_timeout'] = $value / 1000;\n"
" break;\n"
" case CURLOPT_TIMEOUT:\n"
" $this->clientOptions['timeout'] = $value;\n"
" break;\n"
" case CURLOPT_TIMEOUT_MS:\n"
" $this->clientOptions['timeout'] = $value / 1000;\n"
" break;\n"
" case CURLOPT_FILE:\n"
" $this->outputStream = $value;\n"
" break;\n"
" case CURLOPT_HEADER:\n"
" break;\n"
" case CURLOPT_HEADERFUNCTION:\n"
" $this->headerFunction = $value;\n"
" break;\n"
" case CURLOPT_READFUNCTION:\n"
" $this->readFunction = $value;\n"
" break;\n"
" case CURLOPT_WRITEFUNCTION:\n"
" $this->writeFunction = $value;\n"
" break;\n"
" case CURLOPT_PROGRESSFUNCTION:\n"
" $this->progressFunction = $value;\n"
" break;\n"
" case CURLOPT_USERPWD:\n"
" $this->headers['Authorization'] = 'Basic ' . base64_encode($value);\n"
" break;\n"
" case CURLOPT_FOLLOWLOCATION:\n"
" $this->followLocation = $value;\n"
" break;\n"
" case CURLOPT_MAXREDIRS:\n"
" $this->maxRedirs = $value;\n"
" break;\n"
" default:\n"
" throw new swoole_curl_exception(\"option[{$opt}] not supported\");\n"
" }\n"
" return true;\n"
" }\n"
"\n"
" public function reset(): void\n"
" {\n"
" }\n"
"\n"
" public function getInfo()\n"
" {\n"
" return $this->info;\n"
" }\n"
"\n"
" private function unparseUrl(array $parsedUrl): string\n"
" {\n"
" $scheme = ($parsedUrl['scheme'] ?? 'http') . '://';\n"
" $host = $parsedUrl['host'] ?? '';\n"
" $port = isset($parsedUrl['port']) ? ':' . $parsedUrl['port'] : '';\n"
" $user = $parsedUrl['user'] ?? '';\n"
" $pass = isset($parsedUrl['pass']) ? ':' . $parsedUrl['pass'] : '';\n"
" $pass = ($user or $pass) ? \"$pass@\" : '';\n"
" $path = $parsedUrl['path'] ?? '';\n"
" $query = (isset($parsedUrl['query']) and '' !== $parsedUrl['query']) ? '?' . $parsedUrl['query'] : '';\n"
" $fragment = isset($parsedUrl['fragment']) ? '#' . $parsedUrl['fragment'] : '';\n"
" return $scheme . $user . $pass . $host . $port . $path . $query . $fragment;\n"
" }\n"
"\n"
" private function getRedirectUrl(string $location): array\n"
" {\n"
" $uri = parse_url($location);\n"
" if (isset($uri['host'])) {\n"
" $redirectUri = $uri;\n"
" } else {\n"
" if (!isset($location[0])) {\n"
" return [];\n"
" }\n"
" $redirectUri = $this->urlInfo;\n"
" $redirectUri['query'] = '';\n"
" if ('/' === $location[0]) {\n"
" $redirectUri['path'] = $location;\n"
" } else {\n"
" $path = dirname($redirectUri['path'] ?? '');\n"
" if ('.' === $path) {\n"
" $path = '/';\n"
" }\n"
" if (isset($location[1]) and './' === substr($location, 0, 2)) {\n"
" $location = substr($location, 2);\n"
" }\n"
" $redirectUri['path'] = $path . $location;\n"
" }\n"
" foreach ($uri as $k => $v) {\n"
" if (!in_array($k, ['path', 'query'])) {\n"
" $redirectUri[$k] = $v;\n"
" }\n"
" }\n"
" }\n"
" return $redirectUri;\n"
" }\n"
"}\n"
"\n"
"class swoole_curl_exception extends swoole_exception\n"
"{\n"
"\n"
"}\n"
"\n"
"function swoole_curl_init($url = null): swoole_curl_handler\n"
"{\n"
" return new swoole_curl_handler($url);\n"
"}\n"
"\n"
"/**\n"
" * @param swoole_curl_handler $obj\n"
" * @param $opt\n"
" * @param $value\n"
" * @return bool\n"
" * @throws swoole_curl_exception\n"
" */\n"
"function swoole_curl_setopt(swoole_curl_handler $obj, $opt, $value): bool\n"
"{\n"
" return $obj->setOption($opt, $value);\n"
"}\n"
"\n"
"/**\n"
" * @param swoole_curl_handler $obj\n"
" * @param $array\n"
" * @return bool\n"
" * @throws swoole_curl_exception\n"
" */\n"
"function swoole_curl_setopt_array(swoole_curl_handler $obj, $array): bool\n"
"{\n"
" foreach ($array as $k => $v) {\n"
" if ($obj->setOption($k, $v) === false) {\n"
" return false;\n"
" }\n"
" }\n"
" return true;\n"
"}\n"
"\n"
"function swoole_curl_exec(swoole_curl_handler $obj)\n"
"{\n"
" return $obj->execute();\n"
"}\n"
"\n"
"function swoole_curl_close(swoole_curl_handler $obj): void\n"
"{\n"
" $obj->close();\n"
"}\n"
"\n"
"function swoole_curl_error(swoole_curl_handler $obj): string\n"
"{\n"
" return $obj->errMsg;\n"
"}\n"
"\n"
"function swoole_curl_errno(swoole_curl_handler $obj): int\n"
"{\n"
" return $obj->errCode;\n"
"}\n"
"\n"
"function swoole_curl_reset(swoole_curl_handler $obj): void\n"
"{\n"
" $obj->reset();\n"
"}\n"
"\n"
"function swoole_curl_getinfo(swoole_curl_handler $obj, int $opt = 0)\n"
"{\n"
" $info = $obj->getInfo();\n"
" if ($opt) {\n"
" switch ($opt) {\n"
" case CURLINFO_EFFECTIVE_URL:\n"
" return $info['url'];\n"
" case CURLINFO_HTTP_CODE:\n"
" return $info['http_code'];\n"
" case CURLINFO_CONTENT_TYPE:\n"
" return $info['content_type'];\n"
" case CURLINFO_REDIRECT_COUNT:\n"
" return $info['redirect_count'];\n"
" case CURLINFO_REDIRECT_URL:\n"
" return $info['redirect_url'];\n"
" case CURLINFO_TOTAL_TIME:\n"
" return $info['total_time'];\n"
" case CURLINFO_STARTTRANSFER_TIME:\n"
" return $info['starttransfer_time'];\n"
" case CURLINFO_SIZE_DOWNLOAD:\n"
" return $info['size_download'];\n"
" case CURLINFO_SPEED_DOWNLOAD:\n"
" return $info['speed_download'];\n"
" case CURLINFO_REDIRECT_TIME:\n"
" return $info['redirect_time'];\n"
" default:\n"
" return null;\n"
" }\n"
" } else {\n"
" return $info;\n"
" }\n"
"}\n";
static const char* swoole_library_source_core_coroutine_wait_group =
"\n"
"\n"
"namespace Swoole\\Coroutine;\n"
"\n"
"use BadMethodCallException;\n"
"use InvalidArgumentException;\n"
"\n"
"class WaitGroup\n"
"{\n"
" protected $chan;\n"
" protected $count = 0;\n"
" protected $waiting = false;\n"
"\n"
" public function __construct()\n"
" {\n"
" $this->chan = new Channel(1);\n"
" }\n"
"\n"
" public function add(int $delta = 1): void\n"
" {\n"
" if ($this->waiting) {\n"
" throw new BadMethodCallException('WaitGroup misuse: add called concurrently with wait');\n"
" }\n"
" $count = $this->count + $delta;\n"
" if ($count < 0) {\n"
" throw new InvalidArgumentException('negative WaitGroup counter');\n"
" }\n"
" $this->count = $count;\n"
" }\n"
"\n"
" public function done(): void\n"
" {\n"
" $count = $this->count - 1;\n"
" if ($count < 0) {\n"
" throw new BadMethodCallException('negative WaitGroup counter');\n"
" }\n"
" $this->count = $count;\n"
" if ($count === 0 && $this->waiting) {\n"
" $this->chan->push(true);\n"
" }\n"
" }\n"
"\n"
" public function wait(): void\n"
" {\n"
" if ($this->count > 0) {\n"
" $this->waiting = true;\n"
" $this->chan->pop();\n"
" $this->waiting = false;\n"
" }\n"
" }\n"
"}\n";
static const char* swoole_library_source_core_coroutine_object_pool =
"\n"
"\n"
"namespace Swoole\\Coroutine;\n"
"\n"
"use BadMethodCallException;\n"
"use InvalidArgumentException;\n"
"use RuntimeException;\n"
"use Swoole\\Coroutine;\n"
"\n"
"abstract class ObjectPool\n"
"{\n"
" protected static $context = [];\n"
" protected $object_pool;\n"
" protected $busy_pool;\n"
" protected $type;\n"
"\n"
" public function __construct($type, $pool_size = 10, $concurrency = 10)\n"
" {\n"
" if (empty($type)) {\n"
" throw new InvalidArgumentException('ObjectPool misuse: parameter type can not be empty');\n"
" }\n"
" if (!is_numeric($concurrency) || $concurrency <= 0) {\n"
" throw new InvalidArgumentException('ObjectPool misuse: parameter concurrency must larger than 0');\n"
" }\n"
"\n"
" $this->object_pool = new Channel($pool_size);\n"
" $this->busy_pool = new Channel($concurrency);\n"
" $this->type = $type;\n"
" }\n"
"\n"
" public function get()\n"
" {\n"
" $cid = Coroutine::getCid();\n"
" if ($cid < 0) {\n"
" throw new BadMethodCallException('ObjectPool misuse: get must be used in coroutine');\n"
" }\n"
" $type = $this->type;\n"
" $context = Coroutine::getContext();\n"
" Coroutine::defer(function () {\n"
" $this->free();\n"
" });\n"
" if (isset($context[$cid][$type])) {\n"
" return $context[$cid][$type];\n"
" }\n"
" if (!$this->object_pool->isEmpty()) {\n"
" $object = $this->object_pool->pop();\n"
" $context[$cid][\"new\"] = false;\n"
" } else {\n"
" /* create concurrency control */\n"
" $this->busy_pool->push(true);\n"
" $object = $this->create();\n"
" if (empty($object)) {\n"
" throw new RuntimeException('ObjectPool misuse: create object failed');\n"
" }\n"
" $context[$cid][\"new\"] = true;\n"
" }\n"
"\n"
" $context[$cid][$type] = $object;\n"
" return $object;\n"
" }\n"
"\n"
" public function free()\n"
" {\n"
" $cid = Coroutine::getCid();\n"
" if ($cid < 0) {\n"
" throw new BadMethodCallException('ObjectPool misuse: free must be used in coroutine');\n"
" }\n"
" $type = $this->type;\n"
" $context = Coroutine::getContext();\n"
" $object = $context[$cid][$type];\n"
" $this->object_pool->push($object);\n"
" if ($context[$cid][\"new\"]) {\n"
" $this->busy_pool->pop();\n"
" }\n"
" }\n"
"\n"
" abstract function create();\n"
"}\n";
static const char* swoole_library_source_core_string_object =
"\n"
"\n"
"namespace Swoole;\n"
"\n"
"class StringObject\n"
"{\n"
" /**\n"
" * @var string\n"
" */\n"
" protected $string;\n"
"\n"
" /**\n"
" * StringObject constructor.\n"
" * @param $string\n"
" */\n"
" public function __construct(string $string = '')\n"
" {\n"
" $this->string = $string;\n"
" }\n"
"\n"
" /**\n"
" * @return int\n"
" */\n"
" public function length(): int\n"
" {\n"
" return strlen($this->string);\n"
" }\n"
"\n"
" /**\n"
" * @param string $needle\n"
" * @param int $offset\n"
" * @return bool|int\n"
" */\n"
" public function indexOf(string $needle, int $offset = 0)\n"
" {\n"
" return strpos($this->string, $needle, $offset);\n"
" }\n"
"\n"
" /**\n"
" * @param string $needle\n"
" * @param int $offset\n"
" * @return bool|int\n"
" */\n"
" public function lastIndexOf(string $needle, int $offset = 0)\n"
" {\n"
" return strrpos($this->string, $needle, $offset);\n"
" }\n"
"\n"
" /**\n"
" * @param string $needle\n"
" * @param int $offset\n"
" * @return bool|int\n"
" */\n"
" public function pos(string $needle, int $offset = 0)\n"
" {\n"
" return strpos($this->string, $needle, $offset);\n"
" }\n"
"\n"
" /**\n"
" * @param string $needle\n"
" * @param int $offset\n"
" * @return bool|int\n"
" */\n"
" public function rpos(string $needle, int $offset = 0)\n"
" {\n"
" return strrpos($this->string, $needle, $offset);\n"
" }\n"
"\n"
" /**\n"
" * @param string $needle\n"
" * @return bool|int\n"
" */\n"
" public function ipos(string $needle)\n"
" {\n"
" return stripos($this->string, $needle);\n"
" }\n"
"\n"
" /**\n"
" * @return static\n"
" */\n"
" public function lower(): self\n"
" {\n"
" return new static(strtolower($this->string));\n"
" }\n"
"\n"
" /**\n"
" * @return static\n"
" */\n"
" public function upper(): self\n"
" {\n"
" return new static(strtoupper($this->string));\n"
" }\n"
"\n"
" /**\n"
" * @return static\n"
" */\n"
" public function trim(): self\n"
" {\n"
" return new static(trim($this->string));\n"
" }\n"
"\n"
" /**\n"
" * @return static\n"
" */\n"
" public function lrim(): self\n"
" {\n"
" return new static(ltrim($this->string));\n"
" }\n"
"\n"
" /**\n"
" * @return static\n"
" */\n"
" public function rtrim(): self\n"
" {\n"
" return new static(rtrim($this->string));\n"
" }\n"
"\n"
" /**\n"
" * @param int $offset\n"
" * @param mixed ...$length\n"
" * @return static\n"
" */\n"
" public function substr(int $offset, ...$length): self\n"
" {\n"
" return new static(substr($this->string, $offset, ...$length));\n"
" }\n"
"\n"
" /**\n"
" * @param $n\n"
" * @return StringObject\n"
" */\n"
" public function repeat($n)\n"
" {\n"
" return new static(str_repeat($this->string, $n));\n"
" }\n"
"\n"
" /**\n"
" * @param string $search\n"
" * @param string $replace\n"
" * @param null $count\n"
" * @return static\n"
" */\n"
" public function replace(string $search, string $replace, &$count = null): self\n"
" {\n"
" return new static(str_replace($search, $replace, $this->string, $count));\n"
" }\n"
"\n"
" /**\n"
" * @param string $needle\n"
" * @return bool\n"
" */\n"
" public function startsWith(string $needle): bool\n"
" {\n"
" return strpos($this->string, $needle) === 0;\n"
" }\n"
"\n"
" /**\n"
" * @param string $subString\n"
" * @return bool\n"
" */\n"
" public function contains(string $subString): bool\n"
" {\n"
" return strpos($this->string, $subString) !== false;\n"
" }\n"
"\n"
" /**\n"
" * @param string $needle\n"
" * @return bool\n"
" */\n"
" public function endsWith(string $needle): bool\n"
" {\n"
" return strrpos($this->string, $needle) === (strlen($needle) - 1);\n"
" }\n"
"\n"
" /**\n"
" * @param string $delimiter\n"
" * @param int $limit\n"
" * @return ArrayObject\n"
" */\n"
" public function split(string $delimiter, int $limit = PHP_INT_MAX): ArrayObject\n"
" {\n"
" return static::detectArrayType(explode($delimiter, $this->string, $limit));\n"
" }\n"
"\n"
" /**\n"
" * @param int $index\n"
" * @return string\n"
" */\n"
" public function char(int $index): string\n"
" {\n"
" return $this->string[$index];\n"
" }\n"
"\n"
" /**\n"
" * @param int $chunkLength\n"
" * @param string $chunkEnd\n"
" * @return static\n"
" */\n"
" public function chunkSplit(int $chunkLength = 1, string $chunkEnd = ''): self\n"
" {\n"
" return new static(chunk_split($this->string, $chunkLength, $chunkEnd));\n"
" }\n"
"\n"
" /**\n"
" * @param int $splitLength\n"
" * @return ArrayObject\n"
" */\n"
" public function chunk($splitLength = 1): ArrayObject\n"
" {\n"
" return static::detectArrayType(str_split($this->string, $splitLength));\n"
" }\n"
"\n"
" /**\n"
" * @return string\n"
" */\n"
" public function toString()\n"
" {\n"
" return $this->string;\n"
" }\n"
"\n"
" /**\n"
" * @return string\n"
" */\n"
" public function __toString(): string\n"
" {\n"
" return $this->string;\n"
" }\n"
"\n"
" /**\n"
" * @param array $value\n"
" * @return ArrayObject\n"
" */\n"
" protected static function detectArrayType(array $value): ArrayObject\n"
" {\n"
" return new ArrayObject($value);\n"
" }\n"
"}\n";
static const char* swoole_library_source_core_array_object =
"\n"
"\n"
"namespace Swoole;\n"
"\n"
"use ArrayAccess;\n"
"use Countable;\n"
"use Iterator;\n"
"use RuntimeException;\n"
"use Serializable;\n"
"\n"
"class ArrayObject implements ArrayAccess, Serializable, Countable, Iterator\n"
"{\n"
" /**\n"
" * @var array\n"
" */\n"
" protected $array;\n"
"\n"
" /**\n"
" * ArrayObject constructor.\n"
" * @param array $array\n"
" */\n"
" public function __construct(array $array = [])\n"
" {\n"