cyberline/phupnp

PHP based UPnP device discovery

dev-master 2021-10-18 22:12 UTC

This package is auto-updated.

Last update: 2024-10-19 04:40:30 UTC


README

PHP based UPnP device discovery

Build Status Scrutinizer Code Quality Latest Stable Version Total Downloads Latest Unstable Version License

Example

Install using composer

composer require cyberline/phupnp

Discover all devices with timeout of 1 second

namespace CyberLine\phUPnP
{
    require 'src/Scanner.php';

    try {
        $scanner = new Scanner;
        $scanner
            ->setTimeout(1);

        print_r($scanner->discover());
    } catch (\Exception $e) {
        print 'Exception: ' . $e->getMessage() . PHP_EOL;
    }
}

Discover only root devices

namespace CyberLine\phUPnP
{
    require 'src/Scanner.php';

    try {
        $scanner = new Scanner;
        $scanner
            ->setTimeout(1)
            ->setSearchType('upnp:rootdevice');

        print_r($scanner->discover());
    } catch (\Exception $e) {
        print 'Exception: ' . $e->getMessage() . PHP_EOL;
    }
}

Return json string from scanner

namespace CyberLine\phUPnP
{
    require 'src/Scanner.php';

    try {
        print json_encode(new Scanner);
    } catch (\Exception $e) {
        print 'Exception: ' . $e->getMessage() . PHP_EOL;
    }
}