If you're a PHP developer working on a Mac, you might be interested in a handy utility app called PHP Monitor, or phpmon for short. This lightweight app runs in your macOS status bar and displays the active PHP version you're currently using. It's a great tool for developers who regularly switch between different PHP versions and want to quickly check which one is currently active.

PHP Monitor also gives you quick access to various useful functionality (like accessing configuration files, restarting services, and more).

In this blog post, we'll take a closer look at PHP Monitor and its integration with Laravel Valet.

Laravel Valet Integration

One of the most significant benefits of using PHP Monitor is its integration with Laravel Valet. For those unfamiliar with Laravel Valet, it's a popular development environment for macOS that makes it easy to set up local PHP development environments. With PHP Monitor, you can see which PHP version you're currently using with Laravel Valet in your status bar. This feature is particularly useful when you're working on multiple projects that require different PHP versions.

To use PHP Monitor with Laravel Valet, you need to have Valet set up on your Mac. If you haven't already installed Valet, you can do so by following the installation instructions on their website. Once you've installed Valet, you can install PHP Monitor using Homebrew or by downloading the app directly from their website.

Setting up Your Environment

If you're new to using Laravel Valet, you might be wondering how to set up your environment to use PHP Monitor. Fortunately, the developers of PHP Monitor have provided an informative FAQ on their website that covers everything you need to know. They explain how to install Valet, how to use Valet to switch PHP versions, and how to configure PHP Monitor to work with Valet.

Conclusion

In conclusion, PHP Monitor is a fantastic utility app for PHP developers who work on a Mac. Its integration with Laravel Valet makes it an essential tool for developers who frequently switch between different PHP versions. If you're new to using Laravel Valet, it might take a bit of effort to get everything set up correctly, but the benefits of using PHP Monitor are definitely worth it.

How does it work?

Loading info about PHP in the background

This app runs php-config --version in the background periodically, usually whenever your Homebrew configuration is modified. A filesystem watcher is used to determine if anything changes in your Homebrew's bin directory.

PHP Monitor also checks your .ini files for extensions and loads more information about your limits (memory limit, POST limit, upload limit). See also the section on Config change detection below.

Switching PHP versions

This utility will detect which PHP versions you have installed via Homebrew, and then allows you to switch between them.

The switcher will disable all PHP-FPM services not belonging to the version you wish to use, and link the desired version of PHP. Then, it'll restart your desired PHP version's FPM process. This all happens in parallel, so this should be a bit faster than Valet’s switcher.

If you're using Valet 3 or newer, versions of PHP-FPM required to keep isolated sites up and running will also be started or stopped as needed.

Config change detection

PHP Monitor watches your filesystem in the relevant conf.d directory for the currently linked PHP version.

Whenever an .ini file is modified, PHP Monitor will attempt to reload the current information about the active PHP installation.

If an extension or other process writes to a single file a bunch of times in a short span of time (< 1 sec), PHP Monitor will only reload the active configuration information after a while (with a slight delay).

Site detection

  1. Location of your sites: PHP Monitor uses the Valet configuration file to determine which folders to look into. Each folder is scanned and then PHP Monitor will validate if a composer.json file exists to determine the desired PHP version.
  2. Sites secured or not secured: Whether the directory has been secured is determined by checking if a matching certificate exists under Valet's Certificates directory for that site name.
  3. Project type: PHP Monitor checks your composer.json file for "notable dependencies". If you have laravel/framework in your require, there's a good chance the project type is Laravel, after all.
Note If you have linked a folder in Documents, Desktop or Downloads you might need to grant PHP Monitor access to those directories for PHP Monitor to work correctly.

Resources

GitHub - nicoverbruggen/phpmon: Lightweight, native Mac menu bar app that helps you manage multiple PHP installations, locate config files and more. Also interacts with Laravel Valet.
Lightweight, native Mac menu bar app that helps you manage multiple PHP installations, locate config files and more. Also interacts with Laravel Valet. - GitHub - nicoverbruggen/phpmon: Lightweight…