beanstalkd消息队列在生产环境的应用
来源:互联网 发布:excel两张表格数据对比 编辑:程序博客网 时间:2024/06/05 04:41
1
sudo
apt-get
install
beanstalkd
1
vim
/etc/default/beanstalkd
1
2
3
/etc/init
.d
/beanstalkd
start
lsof
-i:11300
/etc/init
.d
/beanstalkd
stop
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/usr/bin/php
<?php
require_once
'Configuration.php'
;
require_once
'Record.class.php'
;
require_once
'BeanStalk.class.php'
;
$now
=time();
$model
=
new
RecordModel ();
$records
=
$model
->checkStartRecord(
$now
);
//print_r($records);
//exit();
$beanstalk
= BeanStalk::open (
array
(
'servers'
=>
array
(
Configuration::
$record_config
[
'beanStak'
]
),
'select'
=>
'random peek'
) );
$beanstalk
->use_tube (
'records'
);
foreach
(
$records
as
$record
) {
$beanstalk
->put ( 0, 0, 10, json_encode (
$record
) );
}
?>
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
<?php
require_once
(
'config.php'
);
require_once
(
'func.php'
);
require_once
(
'BeanStalk.class.php'
);
$beanstalk
= BeanStalk::open(
array
(
'servers'
=>
array
(
$config
[
'beanStak'
] ),
'select'
=>
'random peek'
));
$beanstalk
->watch(
'records'
);
while
(true){
//$beanstalk->watch('records');
$job
=
$beanstalk
->reserve_with_timeout();
if
(
is_object
(
$job
)){
$data
=
$job
->get();
$json
=json_decode(
$data
,true);
print_r(
$json
);
if
(!
empty
(
$json
[
"live_name"
])&&!
empty
(
$json
[
"start_time"
])&&!
empty
(
$json
[
"end_time"
])&&!
empty
(
$json
[
"vod_id"
])){
//print_r($json);
if
(!
empty
(
$json
[
"afterplay"
])&&
$json
[
"afterplay"
]==1)
$cmd
=
"{$config['afterplaycmd']} {$json["
live_name
"]} {$json["
vod_id
"]} {$json['start_time']} {$json['end_time']}"
;
else
$cmd
=
"{$config['recordcmd']} {$json["
live_name
"]} {$json["
vod_id
"]} {$json['start_time']} {$json['end_time']}"
;
echo
$cmd
;
$chkcmd
=
"ps -ef |grep '"
.
$cmd
.
"' |grep -v 'grep'|wc -l"
;
//$chkcmd="ps -ef |wc -l";
//echo $chkcmd;
$count
=system(
$chkcmd
);
//echo $count;
if
(
$count
==0)
{
//system($cmd);
exec
(
$cmd
,
$res
,
$rc
);
//print_r($res);
//print_r($rc);
}
Beanstalk::
delete
(
$job
);
// Delete the job.
$info
=
array
();
$info
[
"vod_id"
]=
$json
[
'vod_id'
];
$info
[
"record_msg"
]=
"startjob"
;
$data
=
array
();
$data
[
"type"
]=
"reciveRecords"
;
$data
[
"message"
]=
$info
;
$url
=
$config
[
'recordStatus'
];
$httpcode
= 200;
$result
= test_api(
$httpcode
,
$url
,
"post"
,json_encode(
$data
));
print_r(
$data
);
}
//$beanstalk->watch('records');
}
sleep(1);
}
?>
另附一个 beanstalkd管理工具
https://github.com/kr/beanstalkd/wiki/Tools
https://github.com/ptrofimov/beanstalk_console
注意这个需要开启PHP短标签支持
php.ini文件里short_open_tag = On
配置lib/include.php中servers
$config = array( 'servers' => array('192.168.0.3:11300','192.168.0.5:11300')) ;
0 0
- beanstalkd消息队列在生产环境的应用
- beanstalkd消息队列在生产环境的应用
- beanstalkd消息队列在生产环境的应用
- beanstalkd消息队列在生产环境的应用
- beanstalkd消息队列的使用【转】
- beanstalkd消息队列
- 消息队列-beanstalkd
- php消息队列beanstalkd使用
- Beanstalkd+Supervisor构建消息队列
- Docker mesos在生产环境的应用
- 消息队列 Beanstalkd 源码解析(一)
- Ceilometer在生产环境应用可行性分析
- 使用Docker在生产环境部署应用
- 在生产环境使用Docker部署应用
- . Net环境下消息队列(MSMQ)对象的应用
- . Net环境下消息队列(MSMQ)对象的应用
- . Net环境下消息队列(MSMQ)对象的应用
- . Net环境下消息队列(MSMQ)对象的应用
- hibernate 自定义枚举类型映射
- 在 Java 中使用 JSON
- Android 身份证扫描
- 不使用USERADD,手动添加用户
- eclipse下svn常见问题
- beanstalkd消息队列在生产环境的应用
- Android进程保活的一般套路
- 基于潘文明至简设计法实现的PWM调制verilog
- MySQL数据库TDSQL架构分析及采用策略扩容流程
- Problem : STL——灵活的线性表
- 安卓权限
- Keli 编译遇到 > *** FATAL ERROR L250: CODE SIZE LIMIT IN RESTRICTED VERSION EXCEEDED
- C++析构函数为什么要为虚函数
- Chaikin A/D Oscillator 收集派发摆荡指标