Download the PHP package sharkydog/mdns without Composer

On this page you can find all versions of the php package sharkydog/mdns. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package mdns

mdns

Multicast DNS (mDNS) resolver and responder with service discovery (DNS-SD) based on ReactPHP

Resolver

The resolver implements React\Dns\Resolver\ResolverInterface, so it can be used in connectors.

Constructor

Responder

It's a "SimpleResponder", because it will only respond to simple queries. Any record type can be added and the responder will answer with one record per message, matching query name to record name. On qtype "ANY", all records matching name will be sent, again one record per message. $cfbit is the "cache-flush bit" from RFC6762, SRV and TXT records created by addService() bellow will have the cache-flush bit set.

Type is one of React\Dns\Model\Message::TYPE_ constants. Single call for deleting a record will delete one record and return true or false if not found. If there are multiple with the same name and type, to delete all run a loop until false is returned.

Service discovery responder

Basic service discovery

The addService() is the key point.

advertiseService() when called will send once all records related to that service instance.

This service discovery still suffers from the same limitation of the SimpleResponder class mentioned above. One answer per message, but additional SRV, TXT, A and AAAA records will be returned. If the reply grows too large, additional records will be sent in separate messages, but only for multicast replies. In unicast replies only the record matched with the query will be sent, additional records will be removed if they do not fit in a single message.

RecordFactory class

New class (SharkyDog\mDNS\RecordFactory) to help create records and validate some parameters. IPv4 and IPv6 addresses are not yet checked thought.

Multiple messages resolver

React resolver will use the first received message, which is proper for DNS, but in mDNS world multiple hosts can answer a query. To return answers from multiple messages, some extensions to SharkyDog\mDNS\React\Resolver and executors need to be made.

A new parameter is added to resolveAll

When $multi is true, the timeout will be turned into time to collect messages. So, no timeout error will be thrown, response will be returned after timeout have passed and if no valid message was received in that time, React will throw NOERROR / NODATA error.

If the resolver was created with $dnsResolver parameter, $multi will be set to false for all domains except .local.

Let's see how many web servers in our network will respond in 2 seconds.

This will return an array of PTRs (targets).

These are service instance names, like instance1._testsvc1._tcp.local from the Service discovery responder example above. Only queried record types (in this case PTRs) should be returned as additional section is not processed.

Now, let's find all service types advertised on the local network.

Should return

Probably many more.

Additional records

Off by default as this can increase the size of the response significantly and it changes the structure of the response array a little.

The additional records are put in additional element of the response array and will always be the last one. Each element in this array is a React\Dns\Model\Record object.

For service discovery, most devices respond on query for _svctype._tcp.local and _services._dns-sd._udp.local with a PTR for an instance of that service in answers section and SRV, TXT, A and AAAA in additional section.

Any records in answers section of the DNS message that do not match the name in the query will be moved to additional.

Responder

Replies to queries for PTR or SRV will add additional records that exist in the responder, added via addRecordIPv4(), addRecordIPv6(), addRecord() or addService().

If the response becomes too big, the additional records will be removed for unicast replies and sent in separate messages for multicast replies. Default message size is 1472 bytes, can be changed with SharkyDog\mDNS\Socket::setPacketSize(). Minimum is 12 bytes (dns message header), maximum is unbound.

Message filter for the resolver

This is a callback that can filter out DNS messages before they are handled by the resolver. The purpose of this filter is to remove unwanted records in multi mode ($multi == true) or to select the exact record in single mode ($multi == false) instead of the first received. This also reflects on what additional records will be included as nothing is used from filtered out messages.

Only messages that have an answer matching query name and type will reach the filter.

Find a specific http server.

From v1.5 filter can receive the query too (React\Dns\Query\Query).

The filter can:

Per query filter

The filter above will be used for all queries. From v1.5 a filter can be set only for the next query. First the global filter will be called then if it doesn't return anything (or returns null) and doesn't throw exception, the per query filter will be called. Parameters are the same, return meaning too.

Discoverer

New class for service discovery.

The SimpleDiscoverer->service() method resolves a given service type (_http._tcp.local), a service instance (server1._http._tcp.local) or the reserved name for all services (_services._dns-sd._udp.local) to an array of SharkyDog\mDNS\Discoverer\Service objects. It will throw an exception on any other name, like some-host.local.

First, the PTR record for the service type is resolved to service instances or other service types in case of _services._dns-sd._udp.local. Then the SRV records for every instance, then A and/or AAAA for the target from the SRV, then the TXT records for every instance.

A service instance will be discarded if no IP address is found for it. The resolved addresses will be in Service->target property as an array of SharkyDog\mDNS\Discoverer\Address objects. IP type (IPv4 or IPv6) can be found in Address->type property: React\Dns\Model\Message::TYPE_A or React\Dns\Model\Message::TYPE_AAAA.

An important thing to note is when this is used with a service type, including the reserved one for all services, the resolving will stop only after the full timeout of the Resolver has passed (default 2s). Results will be returned only after that. This can be changed with the message filter (see above) and the service filter (bellow). A per query message filter can not be used here.

Used with service instance, will resolve without waiting the timeout if SRV and ip addresses were found.

The service() method has few more parameters.

Service filter

This filter applies to the next service() call, after which it will need to be set again if needed.

Returning false will discard the service, but the resolver will continue until timeout. Returning true will stop listening and resolve the promise with the received services.

Observer (v1.8)

The observer class (SharkyDog\mDNS\SimpleObserver) monitors replies sent to the multicast address, including unsolicited messages with service announcements. Discovered services and addresses will be available through callbacks as SharkyDog\mDNS\Observer\Service and SharkyDog\mDNS\Observer\Address objects, which extend SharkyDog\mDNS\Discoverer\Service and SharkyDog\mDNS\Discoverer\Address to add status and expire timеstamp properties. Services and addresses will be cached for their expire time plus a timeout after which they will be removed. While a service or address is cached, all listeners will receive the same object.

Basic usage

This adds a listener for svc1._test_shd._tcp.local service instance and all service events.

Quick reference

Names can be:

Callbacks will be converted to a \Closure object and that needs to be used to remove a listener. First parameter will be an event, second depends on the name the listener is added for.

The stop() method by default will clear all cached services and addresses, use stop(false) to only stop the multicast socket.

Events

Events are a bitmask of constants defined in SimpleObserver class. The last parameter of addListener() can be used to set a list of events that listener will be called for, 0 (default) means all events. Service listeners may also be called with address events for addresses linked to a service, callbacks will receive the service as the second parameter and the address that triggered the event as the third parameter.

Service and address statuses

The SharkyDog\mDNS\Observer\Service->status and SharkyDog\mDNS\Observer\Address->status hold a bitmask of status flags defined as constants.

What is my local IP?

This class was made mostly for fun, but could be useful if for some reason your too many Raspberry Pis do not keep a static ip address. A query will be sent for IPv4 address and a special domain _my_lan_ip._test.local (can be changed) to the mDNS group. If there is a responder, it will reply with the source ip address.


All versions of mdns with dependencies

PHP Build Version
Package Version
Requires php Version >=7.4
react/event-loop Version ^1.5
react/dns Version ^1.13
clue/multicast-react Version ^1.2
ext-sockets Version *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package sharkydog/mdns contains the following files

Loading the files please wait ....