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
8 changed files
with
110 additions
and
108 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 |
---|---|---|
@@ -1,48 +1,54 @@ | ||
<?php | ||
$client = new swoole_client(SWOOLE_SOCK_TCP); | ||
if(!$client->connect('127.0.0.1', 9504)) | ||
{ | ||
$client->set(array( | ||
'open_length_check' => true, | ||
'package_max_length' => 8 * 1024 * 1024, | ||
'package_length_type' => 'N', //see php pack() | ||
'package_length_offset' => 0, | ||
'package_body_offset' => 4, | ||
)); | ||
|
||
if (!$client->connect('127.0.0.1', 9504)) { | ||
exit("connect failed\n"); | ||
} | ||
|
||
for ($l=0; $l < 1; $l++) | ||
{ | ||
$data = ''; | ||
for($i=0; $i< 10; $i++) | ||
{ | ||
$len = rand(10000, 20000); | ||
echo "package length=".($len + 4)."\n"; | ||
send_test3($client, $len); | ||
$func = "send_test" . intval(empty($argv[1]) ? 3 : $argv[1]); | ||
|
||
for ($l = 0; $l < 1; $l++) { | ||
$data = ''; | ||
for ($i = 0; $i < 10; $i++) { | ||
$len = rand(100000, 200000); | ||
echo "send : " . ($len + 4) . "\n"; | ||
$func($client, $len); | ||
} | ||
//echo 'total send size:', strlen($data),"\n"; | ||
//$client->send($data); | ||
sleep(1); | ||
} | ||
|
||
function send_test3($client, $len) | ||
{ | ||
$data = pack('n', $len + 4); | ||
$data .= str_repeat('A', $len).rand(1000, 9999); | ||
|
||
$chunks = str_split($data, 4000); | ||
|
||
foreach($chunks as $ch) | ||
{ | ||
$client->send($ch); | ||
} | ||
echo "package: ".substr($data, -4, 4)."\n"; | ||
$data = pack('N', $len + 4); | ||
$data .= str_repeat('A', $len) . rand(1000, 9999); | ||
$chunks = str_split($data, 4000); | ||
foreach ($chunks as $ch) { | ||
$client->send($ch); | ||
} | ||
$data = $client->recv(); | ||
echo "recv : " . strlen($data) . "\n"; | ||
} | ||
|
||
function send_test2($client, $len) | ||
{ | ||
$data = pack('n', $len + 4); | ||
$data .= str_repeat('A', $len).rand(1000, 9999); | ||
$client->send($data); | ||
$data = pack('N', $len + 4); | ||
$data .= str_repeat('A', $len) . rand(100000, 999999); | ||
$client->send($data); | ||
|
||
$data = $client->recv(); | ||
} | ||
|
||
function send_test1($client, $len) | ||
{ | ||
$client->send(pack('n', $len + 4)); | ||
usleep(10); | ||
$client->send(str_repeat('A', $len).rand(1000, 9999)); | ||
$client->send(pack('N', $len + 4)); | ||
usleep(10); | ||
$client->send(str_repeat('A', $len) . rand(1000, 9999)); | ||
$data = $client->recv(); | ||
} |
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
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