-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
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 |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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, | ||
]); |
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 | ||
} |
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(); |