-
Notifications
You must be signed in to change notification settings - Fork 2
/
tricker.php
73 lines (59 loc) · 1.93 KB
/
tricker.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
/**
* Created by PhpStorm.
* User: baoxulong
* Date: 2018/6/4
* Time: 上午10:05
*/
require "vendor/autoload.php";
//$data_center = new \App\DataCenter\DataCenter();
//$data_center->setDataType('renewal');//
//swoole_timer_tick(5 * 60 * 1000, function ($a) use ($data_center) {
// var_dump($a);
// $data_center->test();
//});
//$data_center->setDataType('refund');
//swoole_timer_tick(4*60*60*1000, function () use ($data_center) {
// $data_center->test();
//});
$serv = new swoole_server('127.0.0.1', 9601, SWOOLE_BASE, SWOOLE_SOCK_TCP);
$serv->set([
'daemonize' => true,
'log_file' => '/tmp/swoole/trick.php',
'worker_num' => 1
]);
$serv->on('WorkerStart', 'workStart');
$serv->on('Receive', function ($serv, $fd, $fromId, $data) {
// 收到数据后发送给客户端
$serv->send($fd, 'Server ' . $data);
});
$serv->on('Finish', function ($serv, $fd) {
echo "Client close." . PHP_EOL;
});
// 客户端断开连接或者server主动关闭连接时 worker进程内调用
$serv->on('Close', function ($serv, $fd) {
echo "Client close." . PHP_EOL;
});
$serv->start();
function workStart($serv, $fd)
{
$datacenter = new \App\DataCenter\DataCenter();
//自动续费
$serv->tick(4 * 3600 * 1000, function ($id) use ($datacenter) {
$datacenter->setDataType('renewal');
$datacenter->action();
app('log')->info('renewal', ['info' => $id, 'type' => 'renewal']);
});
//私有云产品自动续费
$serv->tick(4 * 3600 * 1000, function ($id) use ($datacenter) {
$datacenter->setDataType('siyy');
$datacenter->action();
app('log')->info('siyy', ['info' => $id, 'type' => 'renewal']);
});
//自动退费
// $serv->tick(4 * 3600 * 1000, function ($id) use ($datacenter) {
// $datacenter->setDataType('refund');
// $datacenter->action();
// app('log')->info('refund', ['info' => $id, 'type' => 'renewal']);
// });
}