-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
1,414 additions
and
339 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
/** | ||
* 简单用法示例 | ||
*/ | ||
require dirname(__DIR__) . '/vendor/autoload.php'; | ||
|
||
use Yurun\Util\HttpRequest; | ||
use Yurun\Util\YurunHttp; | ||
use Yurun\Util\YurunHttp\Handler\Swoole; | ||
|
||
YurunHttp::setDefaultHandler(Swoole::class); | ||
|
||
go(function(){ | ||
$http = new HttpRequest; | ||
$http->protocolVersion = '2.0'; | ||
$http->sendHttp2WithoutRecv('https://wiki.swoole.com/', null, 'GET'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
/** | ||
* Http Client | ||
*/ | ||
|
||
use Yurun\Util\HttpRequest; | ||
use Swoole\Coroutine\Channel; | ||
use Yurun\Util\YurunHttp\Http\Psr7\Uri; | ||
|
||
require dirname(__DIR__) . '/vendor/autoload.php'; | ||
|
||
go(function(){ | ||
$uri = new Uri('https://www.taobao.com/'); | ||
|
||
$client = new \Yurun\Util\YurunHttp\Http2\SwooleClient($uri->getHost(), Uri::getServerPort($uri), 'https' === $uri->getScheme()); | ||
$client->connect(); | ||
|
||
$httpRequest = new HttpRequest; | ||
|
||
$count = 10; | ||
$channel = new Channel($count); | ||
for($i = 0; $i < $count; ++$i) | ||
{ | ||
go(function() use($i, $client, $channel, $httpRequest, $uri){ | ||
$request = $httpRequest->header('aaa', 'bbb')->buildRequest($uri, [ | ||
'date' => $i, | ||
], 'POST', 'json'); | ||
$streamId = $client->send($request); | ||
var_dump('send:' . $streamId); | ||
$response = $client->recv($streamId, 3); | ||
$content = $response->body(); | ||
var_dump('recv:' . $response->getStreamId() . ';statusCode:'. $response->getStatusCode(), ';contentLength:' . strlen($content)); | ||
$channel->push(1); | ||
}); | ||
} | ||
$returnCount = 0; | ||
do { | ||
if($channel->pop()) | ||
{ | ||
++$returnCount; | ||
} | ||
} while($returnCount < $count); | ||
|
||
$client->close(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.