-
Notifications
You must be signed in to change notification settings - Fork 102
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
0 parents
commit fd989cb
Showing
110 changed files
with
10,531 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/.idea | ||
/composer.phar | ||
/composer.lock | ||
/vendor |
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,24 @@ | ||
language: php | ||
|
||
php: | ||
- 5.4 | ||
- 5.5 | ||
- 5.6 | ||
- hhvm | ||
|
||
matrix: | ||
allow_failures: | ||
- php: hhvm | ||
|
||
before_script: | ||
- composer install --dev --prefer-source | ||
- sudo rabbitmqctl add_vhost testvhost | ||
- sudo rabbitmqctl add_user testuser testpassword | ||
- sudo rabbitmqctl set_permissions -p testvhost testuser ".*" ".*" ".*" | ||
|
||
|
||
script: | ||
- ./vendor/bin/phpuint | ||
|
||
services: | ||
- rabbitmq |
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,22 @@ | ||
Copyright (c) 2015 Jakub Kulhan <jakub.kulhan@gmail.com> | ||
|
||
Permission is hereby granted, free of charge, to any person | ||
obtaining a copy of this software and associated documentation | ||
files (the "Software"), to deal in the Software without | ||
restriction, including without limitation the rights to use, | ||
copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the | ||
Software is furnished to do so, subject to the following | ||
conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES | ||
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT | ||
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | ||
OTHER DEALINGS IN THE SOFTWARE. |
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,8 @@ | ||
# Bunny | ||
|
||
> Performant pure-PHP AMQP (RabbitMQ) sync/async (ReactPHP) library | ||
|
||
## License | ||
|
||
The MIT license. See `LICENSE` file. |
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,30 @@ | ||
<?php | ||
namespace Bunny; | ||
|
||
require_once __DIR__ . "/../vendor/autoload.php"; | ||
|
||
$c = new Client(); | ||
$ch = $c->connect()->channel(); | ||
|
||
$ch->queueDeclare("bench_queue"); | ||
$ch->exchangeDeclare("bench_exchange"); | ||
$ch->queueBind("bench_queue", "bench_exchange"); | ||
|
||
$t = null; | ||
$count = 0; | ||
|
||
$ch->run(function (Message $msg, Channel $ch, Client $c) use (&$t, &$count) { | ||
if ($t === null) { | ||
$t = microtime(true); | ||
} | ||
|
||
if ($msg->content === "quit") { | ||
printf("Pid: %s, Count: %s, Time: %.4f\n", getmypid(), $count, microtime(true) - $t); | ||
$c->stop(); | ||
} else { | ||
++$count; | ||
} | ||
|
||
}, "bench_queue", "", false, true); | ||
|
||
$c->disconnect(); |
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,46 @@ | ||
<?php | ||
namespace Bunny; | ||
|
||
use Bunny\Async\Client; | ||
use React\Promise; | ||
|
||
require_once __DIR__ . "/../vendor/autoload.php"; | ||
|
||
$c = new Client(); | ||
|
||
$c->connect()->then(function (Client $c) { | ||
return $c->channel(); | ||
|
||
})->then(function (Channel $ch) { | ||
return Promise\all([ | ||
$ch, | ||
$ch->queueDeclare("bench_queue"), | ||
$ch->exchangeDeclare("bench_exchange"), | ||
$ch->queueBind("bench_queue", "bench_exchange"), | ||
]); | ||
|
||
})->then(function ($r) { | ||
/** @var Channel $ch */ | ||
$ch = $r[0]; | ||
|
||
$t = null; | ||
$count = 0; | ||
|
||
return $ch->consume(function (Message $msg, Channel $ch, Client $c) use (&$t, &$count) { | ||
if ($t === null) { | ||
$t = microtime(true); | ||
} | ||
|
||
if ($msg->content === "quit") { | ||
printf("Pid: %s, Count: %s, Time: %.4f\n", getmypid(), $count, microtime(true) - $t); | ||
$c->disconnect()->then(function () use ($c){ | ||
$c->stop(); | ||
}); | ||
|
||
} else { | ||
++$count; | ||
} | ||
}, "bench_queue", "", false, true); | ||
}); | ||
|
||
$c->run(); |
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,46 @@ | ||
<?php | ||
define("N", 1000000); | ||
|
||
function swapEndian64Strrev($s) | ||
{ | ||
return strrev($s); | ||
} | ||
|
||
function swapEndian64Concat($s) | ||
{ | ||
return $s[7] . $s[6] . $s[5] . $s[4] . $s[3] . $s[2] . $s[1] . $s[0]; | ||
} | ||
|
||
function swapEndian64Index($s) | ||
{ | ||
$rs = "00000000"; | ||
$rs[0] = $s[7]; | ||
$rs[1] = $s[6]; | ||
$rs[2] = $s[5]; | ||
$rs[3] = $s[4]; | ||
$rs[4] = $s[3]; | ||
$rs[5] = $s[2]; | ||
$rs[6] = $s[1]; | ||
$rs[7] = $s[0]; | ||
return $rs; | ||
} | ||
|
||
$s = pack("NN", 1, 1); | ||
|
||
$t = microtime(true); | ||
for ($i = 0; $i < N; ++$i) { | ||
swapEndian64Strrev($s); | ||
} | ||
var_dump(microtime(true) - $t); | ||
|
||
$t = microtime(true); | ||
for ($i = 0; $i < N; ++$i) { | ||
swapEndian64Concat($s); | ||
} | ||
var_dump(microtime(true) - $t); | ||
|
||
$t = microtime(true); | ||
for ($i = 0; $i < N; ++$i) { | ||
swapEndian64Index($s); | ||
} | ||
var_dump(microtime(true) - $t); |
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,38 @@ | ||
<?php | ||
namespace Bunny; | ||
|
||
require_once __DIR__ . "/../vendor/autoload.php"; | ||
|
||
$c = new Client(); | ||
$c->connect(); | ||
$ch = $c->channel(); | ||
|
||
$ch->queueDeclare("bench_queue"); | ||
$ch->exchangeDeclare("bench_exchange"); | ||
$ch->queueBind("bench_queue", "bench_exchange"); | ||
|
||
$body = <<<EOT | ||
abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz | ||
abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz | ||
abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz | ||
abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz | ||
abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz | ||
abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz | ||
abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz | ||
abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz | ||
abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz | ||
abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyza | ||
EOT; | ||
|
||
$time = microtime(true); | ||
$max = isset($argv[1]) ? (int) $argv[1] : 1; | ||
|
||
for ($i = 0; $i < $max; $i++) { | ||
$ch->publish($body, [], "bench_exchange"); | ||
} | ||
|
||
echo microtime(true) - $time, "\n"; | ||
|
||
$ch->publish("quit", [], "bench_exchange"); | ||
|
||
$c->disconnect(); |
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,60 @@ | ||
<?php | ||
namespace Bunny; | ||
|
||
use Bunny\Async\Client; | ||
use React\Promise; | ||
|
||
require_once __DIR__ . "/../vendor/autoload.php"; | ||
|
||
$c = new Client(); | ||
|
||
$body = <<<EOT | ||
abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz | ||
abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz | ||
abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz | ||
abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz | ||
abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz | ||
abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz | ||
abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz | ||
abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz | ||
abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz | ||
abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyza | ||
EOT; | ||
|
||
$time = microtime(true); | ||
$max = isset($argv[1]) ? (int) $argv[1] : 1; | ||
|
||
$c->connect()->then(function (Client $c) { | ||
return $c->channel(); | ||
|
||
})->then(function (Channel $ch) { | ||
return Promise\all([ | ||
$ch, | ||
$ch->queueDeclare("bench_queue"), | ||
$ch->exchangeDeclare("bench_exchange"), | ||
$ch->queueBind("bench_queue", "bench_exchange"), | ||
]); | ||
|
||
})->then(function ($r) use ($body, &$time, &$max) { | ||
/** @var Channel $ch */ | ||
$ch = $r[0]; | ||
|
||
$promises = []; | ||
|
||
for ($i = 0; $i < $max; $i++) { | ||
$promises[] = $ch->publish($body, [], "bench_exchange"); | ||
} | ||
|
||
$promises[] = $ch->publish("quit", [], "bench_exchange"); | ||
|
||
return Promise\all($promises); | ||
|
||
})->then(function () use ($c) { | ||
return $c->disconnect(); | ||
|
||
})->then(function () use ($c, &$time) { | ||
echo microtime(true) - $time, "\n"; | ||
$c->stop(); | ||
}); | ||
|
||
$c->run(); |
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,29 @@ | ||
{ | ||
"name": "bunny/bunny", | ||
"description": "RabbitMQ (or generally AMQP 0.9.1) pure-PHP client library (does not require any ext).", | ||
"minimum-stability": "stable", | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Jakub Kulhan", | ||
"email": "jakub.kulhan@gmail.com" | ||
} | ||
], | ||
"require": { | ||
"php": ">=5.4.0", | ||
"psr/log": "~1.0", | ||
"react/event-loop": "~0.4", | ||
"react/promise": "~2.2" | ||
}, | ||
"require-dev": { | ||
"phpunit/phpunit": "~4.5" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Bunny\\": [ | ||
"src/Bunny/", | ||
"test/Bunny" | ||
] | ||
} | ||
} | ||
} |
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,14 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<phpunit | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.5/phpunit.xsd" | ||
bootstrap="vendor/autoload.php" | ||
colors="true"> | ||
|
||
<testsuites> | ||
<testsuite name="Tests"> | ||
<directory suffix="Test.php" phpVersion="5.4.0" phpVersionOperator=">=">test</directory> | ||
</testsuite> | ||
</testsuites> | ||
|
||
</phpunit> |
Oops, something went wrong.