-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add modify process name support Add task support
- Loading branch information
zhoutianliang
committed
Apr 27, 2018
1 parent
225e798
commit faf2810
Showing
8 changed files
with
268 additions
and
12 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,22 @@ | ||
<?php | ||
/** | ||
* Created by PhpStorm. | ||
* User: zhoutianliang01 | ||
* Date: 2018/4/26 | ||
* Time: 15:12 | ||
*/ | ||
|
||
namespace Surf\Examples; | ||
|
||
|
||
use Surf\Ticker\Ticker; | ||
|
||
class HeartbeatTicker extends Ticker | ||
{ | ||
|
||
public function execute() | ||
{ | ||
// TODO: Implement execute() method. | ||
echo "Heartbeat interval " . $this->interval; | ||
} | ||
} |
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,36 @@ | ||
<?php | ||
/** | ||
* Created by PhpStorm. | ||
* User: zhoutianliang01 | ||
* Date: 2018/4/24 | ||
* Time: 16:45 | ||
*/ | ||
|
||
use Swoole\Client; | ||
|
||
$body = [ | ||
'cmdid' => 'Lpl.Gift', | ||
'data' => [ | ||
'propId'=> 10387, | ||
'uid' => 15, | ||
], | ||
]; | ||
// 所有参数数据包 | ||
$body = json_encode($body); | ||
$toType = 11000; | ||
$toIp = -1; | ||
$fromType = 0; | ||
$fromIp = 0; | ||
$nowAskId = crc32(uniqid(microtime(), true)); | ||
$askId2 = 0; | ||
$head = pack('IsIsIII', strlen($body), $toType, $toIp, $fromType, $fromIp, $nowAskId, $askId2); | ||
$body = $head . $body; | ||
|
||
|
||
$client = new Client(SWOOLE_SOCK_TCP); | ||
if (!$client->connect('127.0.0.1', 20002, 0.5)) { | ||
exit("connect failed. Error: {$client->errCode}\n"); | ||
} | ||
$client->send($body); | ||
echo $client->recv(); | ||
$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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
/** | ||
* Created by PhpStorm. | ||
* User: zhoutianliang01 | ||
* Date: 2018/4/26 | ||
* Time: 15:10 | ||
*/ | ||
|
||
require __DIR__ . '/../../vendor/autoload.php'; | ||
|
||
|
||
$config = require __DIR__ . '/../config.php'; | ||
|
||
$config['server'] = 'tcp'; | ||
|
||
$app = new \Surf\Application(__DIR__, [ | ||
'app.config' => $config | ||
]); | ||
|
||
$app->register(new \Surf\Provider\RedisServiceProvider()); | ||
|
||
$app->addTicker(100, \Surf\Examples\HeartbeatTicker::class); | ||
|
||
try { | ||
$app->run(); | ||
} catch (\Surf\Exception\ServerNotFoundException $e) { | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
/** | ||
* Created by PhpStorm. | ||
* User: zhoutianliang01 | ||
* Date: 2018/4/26 | ||
* Time: 14:27 | ||
*/ | ||
|
||
namespace Surf\Ticker; | ||
|
||
|
||
use Pimple\Psr11\Container; | ||
use Swoole\Server; | ||
|
||
abstract class Ticker implements TickerInterface | ||
{ | ||
|
||
/** | ||
* @var null |Container | ||
*/ | ||
protected $container = null; | ||
|
||
/** | ||
* @var null | Server | ||
*/ | ||
protected $server = null; | ||
|
||
/** | ||
* @var int | ||
*/ | ||
protected $interval = 0; | ||
|
||
/** | ||
* @param null|Server $server | ||
*/ | ||
public function setServer(Server $server) | ||
{ | ||
$this->server = $server; | ||
} | ||
|
||
/** | ||
* @param null|Container $container | ||
*/ | ||
public function setContainer(Container $container) | ||
{ | ||
$this->container = $container; | ||
} | ||
|
||
/** | ||
* @param int $interval | ||
*/ | ||
public function setInterval(int $interval) | ||
{ | ||
$this->interval = $interval; | ||
} | ||
} |
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,15 @@ | ||
<?php | ||
/** | ||
* Created by PhpStorm. | ||
* User: zhoutianliang01 | ||
* Date: 2018/4/26 | ||
* Time: 14:25 | ||
*/ | ||
|
||
namespace Surf\Ticker; | ||
|
||
|
||
interface TickerInterface | ||
{ | ||
public function execute(); | ||
} |