繁体   English   中英

使用Asterisk AMI的php分离fread输出的各个部分

[英]seperating parts of the fread output with php for Asterisk AMI

我有一个问题使我在最后几天一直很忙。 我正在使用Asterisk AMI。

AMI给出这样的输出。

    Event: RTCPSent
Privilege: reporting,all
Channel: SIP/1001-00000000
ChannelState: 6
ChannelStateDesc: Up
CallerIDNum: <unknown>
CallerIDName: SIP/1001
ConnectedLineNum: <unknown>
ConnectedLineName: SIP/1001
Language: ja
AccountCode: 
Context: phones
Exten: 1000
Priority: 4
Uniqueid: 1535617422.0
Linkedid: 1535617422.0
To: 111.108.30.208:61987
From: 172.31.21.5:20687
SSRC: 0x5847ea3c
PT: 200(SR)

Event: RTCPReceived
Privilege: reporting,all
Channel: SIP/1001-00000000
ChannelState: 6
ChannelStateDesc: Up
CallerIDNum: <unknown>
CallerIDName: SIP/1001
ConnectedLineNum: <unknown>
ConnectedLineName: SIP/1001
Language: ja
AccountCode: 
Context: phones
Exten: 1000
Priority: 4
Uniqueid: 1535617422.0
Linkedid: 1535617422.0
To: 172.31.21.5:20687
From: 111.108.30.208:61987
RTT: 0.0116
SSRC: 0x235022ee
PT: 200(SR)

Event: RTCPSent
Privilege: reporting,all
Channel: SIP/1000-00000001
ChannelState: 6
ChannelStateDesc: Up
CallerIDNum: 1000
CallerIDName: SIP/1001
ConnectedLineNum: <unknown>
ConnectedLineName: SIP/1001
Language: ja
AccountCode: 
Context: phones
Exten: 
Priority: 1
Uniqueid: 1535617431.1
Linkedid: 1535617422.0
To: 111.108.30.208:61044
From: 172.31.21.5:20349
SSRC: 0x0cb019a0
PT: 200(SR)

Event: RTCPReceived
Privilege: reporting,all
Channel: SIP/1000-00000001
ChannelState: 6
ChannelStateDesc: Up
CallerIDNum: 1000
CallerIDName: SIP/1001
ConnectedLineNum: <unknown>
ConnectedLineName: SIP/1001
Language: ja
AccountCode: 
Context: phones
Exten: 
Priority: 1
Uniqueid: 1535617431.1
Linkedid: 1535617422.0
To: 172.31.21.5:20349
From: 111.108.30.208:61044
RTT: 0.0115
SSRC: 0x00294823
PT: 200(SR)

我使用fread()函数收集输出。

fread($fp, 8192);

[$ fp是上面类似的输出]

这有效,但逐行给出输出。 正确的方法是从空白线到空白线。

    Event: RTCPReceived
Privilege: reporting,all
Channel: SIP/1001-00000000
ChannelState: 6
ChannelStateDesc: Up
CallerIDNum: <unknown>
CallerIDName: SIP/1001
ConnectedLineNum: <unknown>
ConnectedLineName: SIP/1001
Language: ja
AccountCode: 
Context: phones
Exten: 1000
Priority: 4
Uniqueid: 1535617422.0
Linkedid: 1535617422.0
To: 172.31.21.5:20687
From: 111.108.30.208:61987
RTT: 0.0116
SSRC: 0x235022ee
PT: 200(SR)

这样,我可以收集所需的信息并执行以下步骤。

使用fread函数可以做到吗?

我需要阅读信息,例如谁接了电话或挂断电话。

您的输入将一如既往地受到赞赏

不,不可能。

您应该一一读取循环中的行,直到获得空行,并在需要时将其合并到缓冲区中。

通过将空间拆分为一个数组并检查错误日志来使其工作。 这工作得最好,使我有机会阅读所有内容。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM