npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@leafphp/watcher

v0.0.0-development

Published

Simple monitor script for use during development of your PHP apps.

Downloads

9

Readme

Watcher

Watcher is a tool that helps develop PHP based applications by automatically restarting the application when file changes in the directory are detected.

If you are using this package with Leaf, it has already been integrated with the Leaf CLI serve command and so you don't need to do anything to your code to use this package. Simply install the Leaf CLI and run:

leaf serve --watch

NPM version Supporters on Open Collective

Installation

You only need to go through this if you are not using the Leaf CLI.

Either through cloning with git or by using npm (the recommended way):

npm install -g @leafphp/watcher

# or using yarn:
yarn global add @leafphp/watcher

And watcher will be installed globally to your system path.

Usage

watcher wraps your application, so you can pass all the arguments you would normally pass to your app:

leaf-watcher

This will start your local PHP development server on port 8080. You can change this using the port option.

leaf-watcher --port 3000

For CLI options, use the -h (or --help) argument:

leaf-watcher --help

Automatic re-running

watcher was originally written to restart hanging processes such as web servers, but now supports apps that cleanly exit. If your script exits cleanly, watcher will continue to monitor the directory (or directories) and restart the script if there are any changes.

Manual restarting

Whilst watcher is running, if you need to manually restart your application, instead of stopping and restart watcher, you can type rs with a carriage return, and watcher will restart your process.

Running non-PHP scripts

watcher can also be used to execute and monitor other programs. watcher will read the file extension of the script being run and monitor that extension instead of .php if there's no watcher.json:

watcher --exec "python -v" ./app.py

Now watcher will run app.py with python in verbose mode (note that if you're not passing args to the exec program, you don't need the quotes), and look for new or modified files with the .py extension.

Specifying extension watch list

By default, watcher looks for files with the .php, .phtml, .phps, .phpc, .leaf, .ui, .vein, .html, .xml, and .json extensions. If you use the --exec option and monitor app.py watcher will monitor files with the extension of .py. However, you can specify your own list with the -e (or --ext) switch like so:

leaf-watcher --exec js,pug

Now watcher will restart on any changes to files in the directory (or subdirectories) with the extensions .js, .pug.

Ignoring files

By default, watcher will only restart when a PHP/HTML file changes. In some cases you will want to ignore some specific files, directories or file patterns, to prevent watcher from prematurely restarting your application.

This can be done via the command line:

watcher --ignore lib/ --ignore tests/

Or specific files can be ignored:

watcher --ignore lib/index.php

Patterns can also be ignored (but be sure to quote the arguments):

watcher --ignore 'lib/*.php'

Note that by default, watcher will ignore the .git, vendor, coverage and .sass-cache directories and add your ignored patterns to the list.

Application isn't restarting

In some networked environments (such as a container running watcher reading across a mounted drive), you will need to use the legacyWatch: true which enables Chokidar's polling.

Via the CLI, use either --legacy-watch or -L for short:

leaf-watcher -L

Though this should be a last resort as it will poll every file it can find.

Delaying restarting

In some situations, you may want to wait until a number of files have changed. The timeout before checking for new file changes is 1 second. If you're uploading a number of files and it's taking some number of seconds, this could cause your app to restart multiple times unnecessarily.

To add an extra throttle, or delay restarting, use the --delay command:

leaf-watcher --delay 10 app.php

For more precision, milliseconds can be specified. Either as a float:

leaf-watcher --delay 2.5 app.php

Or using the time specifier (ms):

leaf-watcher --delay 2500ms app.php

The delay figure is number of seconds (or milliseconds, if specified) to delay before restarting. So watcher will only restart your app the given number of seconds after the last file change.

License

MIT http://rem.mit-license.org