File tree Expand file tree Collapse file tree 2 files changed +28
-6
lines changed Expand file tree Collapse file tree 2 files changed +28
-6
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
@@ -199,10 +215,12 @@ public function sendRequest($action, array $parameters = [])
199
215
*/
200
216
public function waitResponse ($ allowTimeout = false )
201
217
{
202
- if (!is_resource ($ this ->socket )) {
203
- return [];
204
- }
205
-
218
+ if (!is_resource ($ this ->socket )) {
219
+ return [];
220
+ }
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 ) {
@@ -381,8 +399,8 @@ public function disconnect()
381
399
$ this ->logoff ();
382
400
}
383
401
384
- if (is_resource ($ this ->socket )) {
385
- fclose ($ this ->socket );
402
+ if (is_resource ($ this ->socket )) {
403
+ fclose ($ this ->socket );
386
404
}
387
405
}//end disconnect()
388
406
You can’t perform that action at this time.
0 commit comments