XMPPPHP
来源:互联网 发布:sql如何创建存储过程 编辑:程序博客网 时间:2024/05/23 00:05
发出去:
接受要是个while,死循环,一直开启的后台进程,一直运行的php文件
例如:
long_run.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
include
'XMPPHP/XMPP.php'
;
$conn
=
new
XMPPHP_XMPP(XMPP_SERVER_IP, XMPP_SERVER_PORT, XMPP_SERVER_USER,
XMPP_SERVER_PASSWORD, XMPP_SERVER_DOMAIN);
$to_jid
=
'id'
;
$body
=
'content'
;
$type
=
'chat'
;
try
{
$conn
->connect();
$conn
->processUntil(
'session_start'
);
$conn
->message(
$to_jid
,
$body
,
$type
);
$conn
->disconnect();
echo
$this
->_success_log;
}
catch
(XMPPHP_Exception
$e
) {
die
(
$this
->_error_log);
}
接受要是个while,死循环,一直开启的后台进程,一直运行的php文件
例如:
long_run.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
74
75
76
77
78
79
80
81
<?php
// activate full error reporting
ignore_user_abort(true);
set_time_limit(0);
include_once
dirname(
__FILE__
) .
'/xmppdefine.php'
;
include_once
(dirname(
__FILE__
) .
'/XMPPHP/XMPP.php'
);
$conn
=
new
XMPPHP_XMPP(XMPP_SERVER_IP, XMPP_SERVER_PORT, XMPP_SERVER_USER,
XMPP_SERVER_PASSWORD, XMPP_SERVER_DOMAIN);
$conn
->autoSubscribe();
$vcard_request
=
array
();
try
{
$conn
->connect();
while
(true) {
//!$conn->isDisconnected()
$payloads
=
$conn
->processUntil(
array
(
'message'
,
//'presence',
//'end_stream',
'session_start'
,
//'vcard'
));
foreach
(
$payloads
as
$event
) {
$pl
=
$event
[1];
switch
(
$event
[0]) {
case
'message'
:
//////////////////////消息的接收处理!!!!!!
break
;
case
'presence'
:
;
break
;
case
'session_start'
:
$conn
->getRoster();
$conn
->presence(
$status
=
"Cheese!"
);
break
;
case
'vcard'
:
// check to see who requested this vcard
$deliver
=
array_keys
(
$vcard_request
,
$pl
[
'from'
]);
// work through the array to generate a message
print_r(
$pl
);
$msg
=
''
;
foreach
(
$pl
as
$key
=>
$item
) {
$msg
.=
"$key: "
;
if
(
is_array
(
$item
)) {
$msg
.=
"\n"
;
foreach
(
$item
as
$subkey
=>
$subitem
) {
$msg
.=
" $subkey: $subitem\n"
;
}
}
else
{
$msg
.=
"$item\n"
;
}
}
// deliver the vcard msg to everyone that requested that vcard
foreach
(
$deliver
as
$sendjid
) {
// remove the note on requests as we send out the message
unset(
$vcard_request
[
$sendjid
]);
//$conn->message($sendjid, $msg, 'chat');
}
break
;
}
}
}
}
catch
(XMPPHP_Exception
$e
) {
die
(
"error:"
.
$e
->getMessage());
}
$conn
->disconnect();