diff --git a/src/SSDP/Device.php b/src/SSDP/Device.php index dc05740..a0570a6 100644 --- a/src/SSDP/Device.php +++ b/src/SSDP/Device.php @@ -47,7 +47,11 @@ class Device public static function createFromSchema($url, $ip) { - $xml = simplexml_load_file($url); + $xml = @simplexml_load_file($url); + if (empty($xml)) { + error_log("Unable to retrieve UPnP schema from {$url}"); + return null; + } $spec = $xml->children('urn:schemas-upnp-org:device-1-0'); if (count($spec)>0) { diff --git a/src/SSDP/Discovery.php b/src/SSDP/Discovery.php index 97b901d..670a2bb 100644 --- a/src/SSDP/Discovery.php +++ b/src/SSDP/Discovery.php @@ -47,8 +47,12 @@ class Discovery implements IteratorAggregate foreach ($responses as $response) { // Add the relevant responses to the list if ($response instanceof MSearchResponse) { + $loc = $response->getLocation(); + if (array_key_exists($loc, $this->devices)) { + continue; + } $device = Device::createFromSchema($response->getLocation(), $response->getIp()); - $this->devices[] = $device; + $this->devices[$loc] = $device; } }