PHPackages                             glw/auto-refresh - 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. [HTTP &amp; Networking](/categories/http)
4. /
5. glw/auto-refresh

ActiveLibrary[HTTP &amp; Networking](/categories/http)

glw/auto-refresh
================

A PHP library for auto-refresh using WebSockets

v2.1.2(1y ago)026PHPPHP ^7.3 || ^8.0

Since Aug 7Pushed 1y ago1 watchersCompare

[ Source](https://github.com/Gumillar88/auto-refresh)[ Packagist](https://packagist.org/packages/glw/auto-refresh)[ RSS](/packages/glw-auto-refresh/feed)WikiDiscussions main Synced 2d ago

READMEChangelogDependenciesVersions (4)Used By (0)

Auto-Refresh PHP Library
========================

[](#auto-refresh-php-library)

Description
-----------

[](#description)

Auto-Refresh is a PHP library that enables automatic browser refresh using WebSocket whenever there is a change in the monitored PHP files. This is especially useful during development when you want to see changes live without manual refreshing.

Features
--------

[](#features)

- Monitors changes in PHP files and directories
- Sends signals to the browser for auto-refresh
- Easy to use with simple configuration

Installation
------------

[](#installation)

You can install this library using Composer by running the following command:

```
composer require glw/auto-refresh
```

Add the following JavaScript code to your HTML file to connect to the WebSocket server:

```

    let socket = new WebSocket("ws://localhost:8080");

    socket.onmessage = function(event) {
        if (event.data === 'reload') {
            location.reload(); // Auto-refresh the browser
        }
    };

```

Run the Server

Start the PHP WebSocket server with the following command:

```
php examples/example.php
```

To use the glw/auto-refresh library in Laravel, follow these steps:

1. Install the Library Install the glw/auto-refresh library using Composer:

```
composer require glw/auto-refresh
```

2. Add WebSocket Server to Laravel Create an Artisan command to run the WebSocket server that monitors file changes:

a. Create Artisan Command Run the following command to create an Artisan command:

```
php artisan make:command AutoRefreshServerSide
```

b. Edit Artisan Command Open the newly created command file at app/Console/Commands/AutoRefreshServerSide.php and edit it as follows:

```
