PHP Livereload
, (*1)
php-livereload is a livereload server written in PHP., (*2)
php-livereload uses livereload.js -- a JavaScript file implementing the client side of the LiveReload protocol., (*3)
Install
Install php-livereload from composer., (*4)
{
"require": {
"rickysu/php-livereload": "dev-master"
}
}
Get the command-line php-livereload, (*5)
$ 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, (*6)
Tests
To run the test suite, you need install the dependencies via composer, then
run PHPUnit., (*7)
$ composer install
$ phpunit
Using php-livereload
define a livereload.json in your project root., (*8)
livereload.json, (*9)
{
"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:, (*10)
# 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., (*11)
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., (*12)