rickysu / php-livereload
a livereload server implement by php
Installs: 3 834
Dependents: 0
Suggesters: 0
Security: 0
Stars: 74
Watchers: 3
Forks: 9
Open Issues: 3
Requires
- react/socket: ^0.4.0
- symfony/console: ^2.6||^3.0
- symfony/finder: ^2.6||^3.0
- symfony/http-foundation: ^2.6||^3.0
Requires (Dev)
- phpunit/phpunit: ^4.8
This package is auto-updated.
Last update: 2024-10-14 19:11:56 UTC
README
php-livereload is a livereload server written in PHP.
php-livereload uses livereload.js -- a JavaScript file implementing the client side of the LiveReload protocol.
Install
Install php-livereload from composer.
{ "require": { "rickysu/php-livereload": "dev-master" } }
Get the command-line php-livereload
$ curl -O https://raw.github.com/RickySu/php-livereload/master/dist/reload.phar
$ chmod +x reload.phar
$ sudo mv reload.phar /usr/bin
Install LiveReload Safari/Chrome/Firefox extension
Tests
To run the test suite, you need install the dependencies via composer, then run PHPUnit.
$ composer install
$ phpunit
Using php-livereload
define a livereload.json in your project root.
livereload.json
{ "period": 1, "watch": { "web/css/": "*.css", "web/js/": "*.js", "web/img/": "\\.png|gif|jpg$" } }
- period: monitor file changes every 1 second.
- watch: file and folder you want to watch
Initialize a default livereload.json file.
$ php bin/reload livereload:init
Running Server.
$ php bin/reload server:run
Rolling Your Own Live Reload
If you would like to trigger the live reload server yourself, simply POST files to the URL: http://localhost:35729/changed
.
Or if you rather roll your own live reload implementation use the following example:
# notify a single change
curl http://localhost:35729/changed?files=style.css
# notify using a longer path
curl http://localhost:35729/changed?files=js/app.js
# notify multiple changes, comma or space delimited
curl http://localhost:35729/changed?files=index.html,style.css,docs/docco.css
Or you can bulk the information into a POST request, with body as a JSON array of files.
curl -X POST http://localhost:35729/changed -d '{ "files": ["style.css", "app.js"] }'
# from a JSON file
node -pe 'JSON.stringify({ files: ["some.css", "files.css"] })' > files.json
curl -X POST -d @files.json http://localhost:35729
License
MIT, see LICENSE.