File tree Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -41,6 +41,10 @@ After installing, you can now use it in your code:
41
41
throw new \RuntimeException('Could not connect to Asterisk Management Interface.');
42
42
}
43
43
44
+ // // if you have a looping of command function
45
+ // // set allowTimeout flag to true
46
+ // $ami->allowTimeout();
47
+
44
48
// $result contains the output from the command
45
49
$result = $ami->command('core show channels');
46
50
Original file line number Diff line number Diff line change @@ -93,6 +93,11 @@ class Ami
93
93
*/
94
94
public $ port ;
95
95
96
+ /**
97
+ * @var int Used in waitResponse function to prevent looping when true
98
+ */
99
+ private $ allowTimeout ;
100
+
96
101
/**
97
102
* Event Handlers
98
103
*
@@ -186,6 +191,17 @@ public function sendRequest($action, array $parameters = [])
186
191
return $ response ;
187
192
}//end sendRequest()
188
193
194
+ /**
195
+ * Set global allowTimeout flag
196
+ * it will prevent looping waitResponse function
197
+ *
198
+ * @param boolean $value
199
+ * @return void
200
+ */
201
+ public function allowTimeout ($ value = true )
202
+ {
203
+ $ this ->allowTimeout = boolval ($ value );
204
+ }//end allowTimeout()
189
205
190
206
/**
191
207
* Wait for a response
@@ -203,6 +219,8 @@ public function waitResponse($allowTimeout = false)
203
219
return [];
204
220
}
205
221
222
+ $ allowTimeout = $ this ->allowTimeout ?: $ allowTimeout ;
223
+
206
224
// make sure we haven't already timed out
207
225
$ info = stream_get_meta_data ($ this ->socket );
208
226
if (feof ($ this ->socket ) === true || $ info ['timed_out ' ] === true ) {
You can’t perform that action at this time.
0 commit comments