Skip to content

Commit

Permalink
initialize
Browse files Browse the repository at this point in the history
  • Loading branch information
cclilshy committed Nov 1, 2024
0 parents commit bee4a8f
Show file tree
Hide file tree
Showing 15 changed files with 927 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.idea
workerman-ripple.imi
.php-cs-fixer.cache

/vendor/
composer.lock
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/UniappTool.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

96 changes: 96 additions & 0 deletions .idea/php.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 47 additions & 0 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php declare(strict_types=1);

/**
* Copyright © 2024 cclilshy
* Email: [email protected]
*
* This software is licensed under the MIT License.
* For full license details, please visit: https://opensource.org/licenses/MIT
*
* By using this software, you agree to the terms of the license.
* Contributions, suggestions, and feedback are always welcome!
*/

use PhpCsFixer\Config;
use PhpCsFixer\Finder;

$finder = Finder::create()->in(__DIR__)
->name('*.php')
->notName('*.blade.php');

$config = new Config();

$config->setFinder($finder);
$config->setRiskyAllowed(true);

return $config->setRules([
'@PSR12' => true,
'native_function_invocation' => [
'include' => ['@all'],
'scope' => 'all',
'strict' => true,
],
'native_constant_invocation' => [
'include' => ['@all'],
'scope' => 'all',
'strict' => true,
],
'global_namespace_import' => [
'import_classes' => true,
'import_constants' => true,
'import_functions' => true,
],
'declare_strict_types' => true,
'linebreak_after_opening_tag' => false,
'blank_line_after_opening_tag' => false,
'no_unused_imports' => true,
]);
29 changes: 29 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"name": "cclilshy/workerman-ripple",
"autoload": {
"psr-4": {
"Workerman\\Ripple\\": "src/"
}
},
"authors": [
{
"name": "cclilshy",
"email": "[email protected]"
}
],
"require": {
"php": ">=8.1",
"ext-pcntl": "*",
"ext-posix": "*",
"ext-sockets": "*",
"cloudtay/ripple": "^1.0",
"walkor/workerman": "^4.1",
"cloudtay/ripple-http": "^0.3.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "*",
"phpunit/phpunit": "*"
},
"minimum-stability": "dev",
"prefer-stable": true
}
47 changes: 47 additions & 0 deletions example/example.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php declare(strict_types=1);

include __DIR__ . '/../vendor/autoload.php';

use Workerman\Connection\TcpConnection;
use Workerman\Ripple\Driver;
use Workerman\Ripple\Utils;
use Workerman\Worker;

$worker = new Worker('text://127.0.0.1:8001');

$worker->onWorkerStart = static function () {
$asyncTcpConnection = Utils::asyncTcpConnection('ssl://www.google.com:443');
$asyncTcpConnection->onConnect = static function (TcpConnection $connection) {
echo 'Connected to google.com' , \PHP_EOL;
$connection->send("GET / HTTP/1.1\r\nHost: www.google.com\r\nConnection: close\r\n\r\n");
};

$asyncTcpConnection->onMessage = static function (TcpConnection $connection, string $data) {
echo 'Received data from google.com: ' . \substr($data, 0, 10),'...' . \PHP_EOL;
};

$asyncTcpConnection->connectViaProxy('socks5://127.0.0.1:1080');
};

$worker->onMessage = static function (TcpConnection $connection, string $data) {
switch (\trim($data, "\n\r\t\v\0")) {
case 'ping':
\Co\sleep(1);
$connection->send('pong');
break;
case 'curl':
try {
$guzzle = Utils::guzzle();
$response = $guzzle->get('https://www.baidu.com');
$connection->send('status: ' . $response->getStatusCode());
} catch (Throwable $e) {
$connection->send('error: ' . $e->getMessage());
}
break;
default:
$connection->send('Invalid command');
}
};

Worker::$eventLoopClass = Driver::class;
Worker::runAll();
Loading

0 comments on commit bee4a8f

Please sign in to comment.