I am trying to write a php script which can scan the network for any mDNS records, and return the results.
'dns-sd -B _roomcast-capi._tcp'
I am working on OSx - from what I understand this command does not work on windows without installing extra SW.
The problem is that this unix command is not working with shell_exec or anything similar.. The PHP just hangs, and I'm left waiting for a non-existent response.
I have tried running the command through shell_exec(), exec(), system(), proc_open() & passthru() - no idea what they do differently, but they all have the same result.. I have also tried redirecting the STDERR output and that didn't seem to make a difference.
One of my attempts..
$p = shell_exec("dns-sd -B _roomcast-capi._tcp 2>&1");
echo($p);
Another attempt...
$descspec = array(
0 => array("pipe", "r"),
1 => array("pipe", "w"),
2 => array("file", "error-output.txt", "a")
);
$process = proc_open('dns-sd -B _roomcast-capi._tcp', $descspec, $pipes);
foreach($pipes as $pipe) {
var_dump($pipe);
// echo "$process<br />";
}
I could list the rest of my attempts here but they're probably all wrong if I'm honest.. PHP is not my strongest area.
You can see here when i run the command in terminal, i can get a response almost immediately.
I have noticed that when i run this command in the terminal on my mac i have to terminate the response with Ctrl+C - could this be the reason for shell_exec not terminating?