I'm getting successful output when I issue the following in a PHP script:
$peers_summary = exec('sudo asterisk -x "sip show peers"', $sip_peers);
$sip_peers
contains the full output of the exec command, listing the peers in standard table format that Asterisk provides. However, when I issue:
$test = exec('sudo asterisk -x "sip show peer trunk-to-pbx"', $trunk);
$trunk
is completely empty: array(0) {}
, and $test
is an empty string: string(0) ""
trunk-to-pbx
is a valid peer in my Asterisk installation, and I've verified that issuing sudo asterisk -x "sip show peer trunk-to-pbx"
at the prompt is successful (as is sudo asterisk -x "sip show peers"
), so I'm not sure why the second command returns empty from exec()
. I thought initially that it might be an output character limit, but the output has less than 2,000 characters - couldn't be a memory or limit issue. I tried set_time_limit(0)
even though the execution is virtually instantaneous at the prompt.
Why is the second exec()
returning empty?
The problem was not with exec()
, or asterisk
, or the command I was passing to exec()
; there's a sudoers
file that whitelists commands, and my command needed inclusion before the exec()
would work. Inherited codebase. Thanks Chris Stryczynski , for your suggestions.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.