tomnomnom / phpwol
Wake On LAN for PHP
Requires (Dev)
- phpunit/phpunit: 3.7.*
This package is not auto-updated.
Last update: 2024-11-09 15:39:27 UTC
README
Send Wake On LAN packets with PHP.
Contents
Installation
Phpwol is available on Packagist so you can
install it using Composer. Just specify it as a dependency in your
composer.json
:
{ "require": { "tomnomnom/phpwol": "0.1.0" } }
Then run composer install
:
▶ composer install
Loading composer repositories with package information
Installing dependencies
- Installing tomnomnom/phpwol (0.1.0)
Downloading: 100%
Writing lock file
Generating autoload files
Once installed you can use the Composer autoloader instead of the one provided in ./Phpwol/Init.php
:
<?php require __DIR__.'/vendor/autoload.php'; $f = new \Phpwol\Factory(); $m = $f->magicPacket();
Usage
A \Phpwol\MagicPacket
object is used to send a WOL packet. Such an object is availble via the \Phpwol\Factory::magicPacket()
method.
<?php // ./Examples/Basic.php require __DIR__.'/../Phpwol/Init.php'; $f = new \Phpwol\Factory(); $magicPacket = $f->magicPacket(); $macAddress = '50:46:5C:53:94:25'; $broadcastIP = '192.168.1.255'; $result = $magicPacket->send($macAddress, $broadcastIP); if ($result){ echo "Worked\n"; } else { echo "Failed\n"; }
▶ php ./Examples/Basic.php
Worked
If you don't know what the broadcast IP is and don't know how to work it out, you can just specify the IP and subnet mask and everything will be worked out for you.
<?php // ./Examples/UnknownBroadcast.php require __DIR__.'/../Phpwol/Init.php'; $f = new \Phpwol\Factory(); $magicPacket = $f->magicPacket(); $macAddress = '50:46:5C:53:94:25'; $ip = '192.168.1.10'; $subnet = '255.255.255.0'; $result = $magicPacket->send($macAddress, $ip, $subnet); if ($result){ echo "Worked\n"; } else { echo "Failed\n"; }
▶ php ./Examples/UnknownBroadcast.php
Worked
Requirements
- Linux of some description
- PHP 5.3 or newer
Testing
You can run the tests by running:
▶ phpunit
The repo is hooked up to Travis CI. You can see the state of the master branch and the build history on the Phpwol Travis CI page. The full test suite runs under PHP 5.3 and PHP 5.4.