PHPackages                             webthing/webthing - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. webthing/webthing

ActiveLibrary[API Development](/categories/api)

webthing/webthing
=================

A PHP Web Thing Server implementation.

v0.0.2(6y ago)24223[1 issues](https://github.com/maliknaik16/webthing-php/issues)MPL-2.0PHP

Since Jan 15Pushed 3y ago2 watchersCompare

[ Source](https://github.com/maliknaik16/webthing-php)[ Packagist](https://packagist.org/packages/webthing/webthing)[ Docs](https://github.com/maliknaik16/webthing-php)[ RSS](/packages/webthing-webthing/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependencies (6)Versions (4)Used By (0)

Web of Things
=============

[](#web-of-things)

[![travis](https://camo.githubusercontent.com/fba3154202f404cdeebc5abafda4d2028d007ff1760b7b5c8aa7f2f506d39df4/68747470733a2f2f6170692e7472617669732d63692e6f72672f6d616c696b6e61696b31362f7765627468696e672d7068702e7376673f6272616e63683d6d6173746572)](https://travis-ci.com/maliknaik16/webthing-php)[![GitHub forks](https://camo.githubusercontent.com/7a299446e955654f0557777aeac46228af4367c54168797c52fbc834fe9ba8ab/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f666f726b732f6d616c696b6e61696b31362f7765627468696e672d706870)](https://github.com/maliknaik16/webthing-php/network/)[![GitHub version](https://camo.githubusercontent.com/ef2d1b42365e777f28dc5112ac14d996679f3e67fa31bd0de19af002be522a22/68747470733a2f2f62616467652e667572792e696f2f67682f6d616c696b6e61696b31362532467765627468696e672d7068702e737667)](https://badge.fury.io/gh/maliknaik16%2Fwebthing-php)[![Source Code](https://camo.githubusercontent.com/7097f51fda5b54f319b0d53864f794e712004d5de90b1f5deccd8e6b1c8a849c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f736f757263652d6d616c696b6e61696b31362532467765627468696e672d2d7068702d626c75653f7374796c653d666c61742d737175617265)](https://github.com/maliknaik16/webthing-php)[![PHP Version](https://camo.githubusercontent.com/aea2d6fe5e7247325a09dcfc4738ae9d923104f34f482a244bfe765975879814/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d372e342532422d6f72616e6765)](https://php.net)[![Software License](https://camo.githubusercontent.com/a2e0ec661ed5254d6ab2dcb24351ded5f2fadbea1d43fe4ed2f8fc4903a9c1a8/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d504c2d2d322e302d677265656e3f7374796c653d666c61742d737175617265)](https://github.com/maliknaik16/webthing-php/blob/master/LICENSE.txt)

Implementation of an HTTP [Web Thing](https://iot.mozilla.org/wot/). This library is compatible with PHP 7.4+.

Installation
============

[](#installation)

The `webthing` can be installed using `composer` via the following command:

```
composer require webthing/webthing:^0.0.1
```

Running the Example
===================

[](#running-the-example)

The following list of commands clones this repository and installs all dependencies using the composer and runs the `single-thing.php` example.

```
git clone https://github.com/maliknaik16/webthing-php.git
cd webthing-php
composer install
php examples/single-thing.php
```

Example Implementation
======================

[](#example-implementation)

In this code-walkthrough we will set up a dimmable light and a humidity sensor (both using fake data, of course). Both working examples can be found in [here](https://github.com/maliknaik16/webthing-php/tree/master/examples).

Dimmable Light
--------------

[](#dimmable-light)

Imagine you have a dimmable light that you want to expose via the web of things API. The light can be turned on/off and the brightness can be set from 0% to 100%. Besides the name, description, and type, a [Light](https://iot.mozilla.org/schemas/#Light) is required to expose two properties:

- `on`: the state of the light, whether it is turned on or off

    - Setting this property via a `PUT {"on": true/false}` call to the REST API toggles the light.
- `brightness`: the brightness level of the light from 0-100%

    - Setting this property via a PUT call to the REST API sets the brightness level of this light.

First we create a new Thing:

```
$light = new Thing(
  'urn:dev:ops:my-lamp-1234',
  'My Lamp',
  ['OnOffSwitch', 'Light'],
  'A web connected lamp'
);
```

Now we can add the required properties.

The `on` property reports and sets the on/off state of the light. For this, we need to have a `Value` object which holds the actual state and also a method to turn the light on/off. For our purposes, we just want to log the new state if the light is switched on/off.

```
$light->addProperty(new Property(
  $light,
  'on',
  new Value(TRUE, function($v) {
    echo "On-State is now " . $v . "\n";
  }),
  [
    '@type' => 'OnOffProperty',
    'title' => 'On/Off',
    'type' => 'boolean',
    'description' => 'Whether the lamp is turned on',
  ])
);
```

The `brightness` property reports the brightness level of the light and sets the level. Like before, instead of actually setting the level of a light, we just log the level.

```
$light->addProperty(new Property(
  $light,
  'brightness',
  new Value(50, function($v) {
    echo "Brightness is now " . $v . "\n";
  }),
  [
    '@type' => 'BrightnessProperty',
    'title' => 'Brightness',
    'type' => 'integer',
    'description' => 'The level of light from 0-100',
    'minimum' => 0,
    'maximum' => 100,
    'unit' => 'percent',
  ])
);
```

Now we can add our newly created thing to the server and start it:

```
// If adding more than one thing, use MultipleThings() with a name.
// In the single thing case, the thing's name will be broadcast.
$server = new WebThingServer(new SingleThing($thing), '127.0.0.1', 8888, 8081);

$server->start();
$server->startWebSocket();
```

This will start the server, making the light available via the WoT REST API and announcing it as a discoverable resource on your local network via mDNS.

Sensor
------

[](#sensor)

Let's now also connect a humidity sensor to the server we set up for our light.

A [MultiLevelSensor](https://iot.mozilla.org/schemas/#MultiLevelSensor) (a sensor that returns a level instead of just on/off) has one required property (besides the name, type, and optional description): `level`. We want to monitor this property and get notified if the value changes.

First we create a new Thing:

```
$sensor = new Thing(
 'urn:dev:ops:my-humidity-sensor-1234',
  'My Humidity Sensor',
  ['MultiLevelSensor'],
  'A web connected humidity sensor'
);
```

Then we create and add the appropriate property:

- `level`: tells us what the sensor is actually reading

    - Contrary to the light, the value cannot be set via an API call, as it wouldn't make much sense, to SET what a sensor is reading. Therefore, we are creating a **readOnly** property.

        ```
        $level = new Value(0.0);
        $sensor->addProperty(new Property(
          $sensor,
          'level',
          $level,
          [
            '@type' => 'LevelProperty',
            'title' => 'Humidity',
            'type' => 'number',
            'description' => 'The current humidity in %',
            'minimum' => 0,
            'maximum' => 100,
            'unit' => 'percent',
            'readOnly' => TRUE,
          ])
        );
        ```

Now we have a sensor that constantly reports 0%. To make it usable, we need a thread or some kind of input when the sensor has a new reading available. For this purpose we start a thread that queries the physical sensor every few seconds. For our purposes, it just calls a fake method.

```
// $level is a `Value` object.
// $loop is a `React\EventLoop\Factory` object.
$loop->addPeriodicTimer(7, function() use ($level) {
  $new_level = readFromGpio();
  printf("Setting new humidity level: %s\n", $new_level);
  $level->notifyOfExternalUpdate($new_level);
});

function readFromGpio() {
  return abs(70.0 * rand() * (-0.5 + rand()));
}
```

This will update our `Value` object with the sensor readings via the `$level->notifyOfExternalUpdate(readFromGpio());` call. The `Value` object now notifies the property and the thing that the value has changed, which in turn notifies all websocket listeners.

Resources
=========

[](#resources)

-
-
-
-

License
=======

[](#license)

Mozilla Public License Version 2.0

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

2315d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/16598038?v=4)[maliknaik](/maintainers/maliknaik)[@maliknaik](https://github.com/maliknaik)

---

Top Contributors

[![maliknaik16](https://avatars.githubusercontent.com/u/6859756?v=4)](https://github.com/maliknaik16 "maliknaik16 (94 commits)")

---

Tags

frameworkhttpiotmozillaphpsensorswebthingsphpmozillawebthing

### Embed Badge

![Health badge](/badges/webthing-webthing/health.svg)

```
[![Health](https://phpackages.com/badges/webthing-webthing/health.svg)](https://phpackages.com/packages/webthing-webthing)
```

###  Alternatives

[php-opencloud/openstack

PHP SDK for OpenStack APIs. Supports BlockStorage, Compute, Identity, Images, Networking and Metric Gnocchi

2292.2M24](/packages/php-opencloud-openstack)[allure-framework/allure-php-api

Allure PHP commons

3411.1M7](/packages/allure-framework-allure-php-api)[ezsystems/allure-php-api

PHP API for Allure adapter

13431.1k11](/packages/ezsystems-allure-php-api)[rubix/server

Deploy your Rubix ML models to production with scalable stand-alone inference servers.

632.3k](/packages/rubix-server)[wayofdev/laravel-symfony-serializer

📦 Laravel wrapper around Symfony Serializer.

2113.6k](/packages/wayofdev-laravel-symfony-serializer)[bornfight/erste-bank-client

Client written in PHP for Erste Bank API

106.1k](/packages/bornfight-erste-bank-client)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
