File tree 6 files changed +57
-8
lines changed
6 files changed +57
-8
lines changed Original file line number Diff line number Diff line change 1
1
composer.lock
2
+ package-lock.json
2
3
vendor
3
- logs
4
+ node_modules
5
+ logs
Original file line number Diff line number Diff line change 8
8
9
9
- ** 使用场景:**
10
10
11
- 常见于Webhook的实现中
11
+ 消息推送,但不考虑结果状态
12
12
13
13
- ** 代码片段**
14
14
15
- > framework/src/Request.class.php
15
+ > framework/src/Request.class.php
16
16
17
17
### 2.2 ** Promise**
18
18
19
+ - ** 相关简介:**
20
+
21
+
22
+
19
23
- ** 使用场景:**
20
24
21
- 常见于Webhook的实现中
25
+ 并发获取资源
22
26
23
27
- ** 代码片段**
24
28
25
- > framework/src/Request.class.php
29
+ > framework/src/Request.class.php
26
30
27
31
### 2.3 ** Redis pipeline**
32
+
33
+
28
34
### 2.4 ** AMQP**
29
35
### 2.5 ** MySQL BatchInsert**
30
36
### 2.6 ** Deamon Process**
Original file line number Diff line number Diff line change 12
12
13
13
use Monolog \Logger ;
14
14
use Monolog \Handler \StreamHandler ;
15
+ use GuzzleHttp \Client ;
16
+ use GuzzleHttp \Promise ;
17
+ use Psr \Http \Message \ResponseInterface ;
15
18
16
19
$ loglevel = defined ('RUN_MODE ' ) && RUN_MODE === 'production ' ? Logger::NOTICE : Logger::DEBUG ;
17
20
$ logger = new Logger ('cobolphp ' );
18
21
$ logger ->pushHandler (new StreamHandler (LOG_PATH . '/access.log ' , $ loglevel ));
19
22
20
23
// 非阻塞请求
21
24
$ request = new \cobolphp \Request ($ logger );
22
- $ request ->asyncRequest ('http://shujuguan.cn ' );
25
+ $ request ->asyncRequest ('http://localhost:8008 ' );
23
26
24
27
// Promise
25
-
28
+ $ client = new Client ();
29
+ $ promises = [];
30
+ for ($ i = 0 ; $ i < 10 ; ++$ i ) {
31
+ $ promise = $ client ->requestAsync (
32
+ 'GET ' ,
33
+ 'http://localhost:8008 '
34
+ );
35
+ $ promise
36
+ ->then (function (ResponseInterface $ response ) {
37
+ echo $ response ->getBody () . PHP_EOL ;
38
+ });
39
+ $ promises [] = $ promise ;
40
+ }
41
+ Promise \all ($ promises )->wait ();
Original file line number Diff line number Diff line change
1
+ const http = require ( 'http' ) ;
2
+ const sleep = require ( 'sleep-async' ) ( ) ;
3
+
4
+ const server = http . createServer ( ) ;
5
+ const sleepMiliSecond = 1000 ;
6
+
7
+ server . on ( 'request' , function ( req , res ) {
8
+ console . log ( 'Received.' ) ;
9
+
10
+ sleep . sleep ( sleepMiliSecond , function ( ) {
11
+ res . writeHead ( 200 , { 'Content-Type' : 'text/json' } ) ;
12
+ res . write ( '{"status": "ok"}' ) ;
13
+ res . end ( ) ;
14
+ } ) ;
15
+ } ) ;
16
+
17
+ server . listen ( 8008 , 'localhost' ) ;
Original file line number Diff line number Diff line change 1
1
{
2
2
"require" : {
3
- "monolog/monolog" : " ^1.23"
3
+ "monolog/monolog" : " ^1.23" ,
4
+ "guzzlehttp/guzzle" : " ^6.3"
4
5
},
5
6
"require-dev" : {
6
7
"psecio/iniscan" : " ^3.6"
Original file line number Diff line number Diff line change
1
+ {
2
+ "name" : " cobolphp/framework" ,
3
+ "description" : " Strive to break through" ,
4
+ "dependencies" : {
5
+ "sleep-async" : " ^1.0.5"
6
+ }
7
+ }
You can’t perform that action at this time.
0 commit comments