A complete "Live Reload" feature for PHP projects in a single class

Felippe Regazio - Jan 9 '19 - - Dev Community

WARNING:This project has changed A LOT since the publication date of this post. It still offers a hot reload feature in a single class, but now with a SSE (Server-Sent Events) approach. Take a look on the github docs to further information

Recently i made this PHP class to use in my personal projects and in the company which i work for. I really enjoy the Vue (and other frameworks) Hot Reload capabilities and i became kinda badly accustomed with this new features, so i wrote this class to add a live reload feature to any php project in a very simple way. It allows you to see your page dinamically changing while coding, without have to keep refreshing the browser on every change. By default, the script will turn your project tab reactive to changes in included/required files, css and js files releated to the tab opened. Every browser, every project, one single file.

The use is really simple: You must call the HotReloader on the sources you want to auto-react to changes. The reactions will happen on js, css, and other php files related to current page. You must have a layout file, common footer or something like this in your boilerplate. If dont, you'll need to put the HotReloader() in your code manually. The examples here must be putted on your footer section or somewhere after your <body> tag.

The simplest way to start is: require the class, instantiate it, call the init method. Now, keep the page opened while coding, and just code.

require "../hotreloader.php";
$reloader = new HotReloader();
$reloader->init();
Enter fullscreen mode Exit fullscreen mode

You can change, expand and adapt this default behavior, and you can configure the class to a better experience in according to your needings. Different from other live reloaders i have seen in php, by default this will not assist your entire directory, but only files related to your current page. I have using this class in huge projects and inside frameworks as Cake Php, and its behavior its been really acceptable and lightweight. The project is a BETA version, to download or read the documentation, please see the Github page. Contributors are really wellcome ;)

https://github.com/felippe-regazio/php-hot-reloader

Hope you enjoy!

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Terabox Video Player