duandongji2231 2018-08-30 08:35
浏览 139

使用PHP为Asterisk AMI分离fread输出的部分内容

I have a question that has kept me busy for the last days. I am working with the Asterisk AMI.

The AMI gives output like this.

    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)

I collect the output with the fread() function.

fread($fp, 8192);

[$fp is the output like here above]

This works but gives the output line by line. The correct way to get this would be from a white space line till white space line.

    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)

This way I could collect the information that is needed and do the following steps.

Is this possible with the fread function?

I need to read information like who picked up the phone or hangeup.

Your input would be as always highly appreciated

  • 写回答

2条回答 默认 最新

  • duanpo2813 2018-08-30 08:45
    关注

    No, not possible.

    You should read lines in loop one-by-one until get empty line and merge it in buffer if needed.

    评论

报告相同问题?

悬赏问题

  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行