Skip to content

Commit 50f6afb

Browse files
πŸ”€ Merge branch 'develop'
* develop: ✨ Add option to restart nginx, open valet config ✨ Allow restarting of PHP-FPM πŸ“ Update copyright message
2 parents b792f55 + 67e80aa commit 50f6afb

File tree

6 files changed

+120
-23
lines changed

6 files changed

+120
-23
lines changed

β€ŽPHP Monitor.xcodeproj/project.pbxprojβ€Ž

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -365,14 +365,14 @@
365365
CODE_SIGN_IDENTITY = "-";
366366
CODE_SIGN_STYLE = Automatic;
367367
COMBINE_HIDPI_IMAGES = YES;
368-
CURRENT_PROJECT_VERSION = 17;
368+
CURRENT_PROJECT_VERSION = 18;
369369
DEVELOPMENT_TEAM = 8M54J5J787;
370370
INFOPLIST_FILE = phpmon/Info.plist;
371371
LD_RUNPATH_SEARCH_PATHS = (
372372
"$(inherited)",
373373
"@executable_path/../Frameworks",
374374
);
375-
MARKETING_VERSION = 1.7;
375+
MARKETING_VERSION = 1.8;
376376
PRODUCT_BUNDLE_IDENTIFIER = com.nicoverbruggen.phpmon;
377377
PRODUCT_NAME = "$(TARGET_NAME)";
378378
SWIFT_VERSION = 5.0;
@@ -387,14 +387,14 @@
387387
CODE_SIGN_IDENTITY = "-";
388388
CODE_SIGN_STYLE = Automatic;
389389
COMBINE_HIDPI_IMAGES = YES;
390-
CURRENT_PROJECT_VERSION = 17;
390+
CURRENT_PROJECT_VERSION = 18;
391391
DEVELOPMENT_TEAM = 8M54J5J787;
392392
INFOPLIST_FILE = phpmon/Info.plist;
393393
LD_RUNPATH_SEARCH_PATHS = (
394394
"$(inherited)",
395395
"@executable_path/../Frameworks",
396396
);
397-
MARKETING_VERSION = 1.7;
397+
MARKETING_VERSION = 1.8;
398398
PRODUCT_BUNDLE_IDENTIFIER = com.nicoverbruggen.phpmon;
399399
PRODUCT_NAME = "$(TARGET_NAME)";
400400
SWIFT_VERSION = 5.0;

β€ŽREADME.mdβ€Ž

Lines changed: 49 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,20 @@
11
# PHP Monitor
22

3-
PHP Monitor (or phpmon) is a macOS utility that runs on your Mac and displays the active PHP version in your status bar.
3+
PHP Monitor (or phpmon) is a macOS utility that runs on your Mac and displays the active PHP version in your status bar. It also gives you quick access to various useful functionality (like switching PHP versions, restarting services, accessing configuration files, and more).
44

55
<img src="./docs/screenshot.png" width="278px" alt="phpmon screenshot"/>
66

77
For me, it comes in handy when running multiple versions of PHP with Homebrew and you wish to be able to see at a glance which version is currently linked & active with Laravel Valet, and switch between versions.
88

99
## System requirements
1010

11-
**Minimal system requirements**
12-
13-
* macOS 10.14 or higher
14-
* PHP 7.4 installed via Homebrew
15-
* Laravel Valet 2.3 or higher installed
16-
17-
**Recommended system**
18-
1911
* macOS 10.15 Catalina
20-
* PHP 7.4 installed with Homebrew 2.2
12+
* PHP 7.4 installed with Homebrew 2.x
2113
- other versions of PHP are optional
2214
- includes support for PHP 5.6 and PHP 7.0 [as well](https://github.com/eXolnet/homebrew-deprecated)
23-
* Laravel Valet 2.5.x installed
15+
* Laravel Valet 2.8
16+
17+
If you're looking to run PHP Monitor in combination with an older version of macOS or Laravel Valet, please check out the older releases of the software.
2418

2519
## Why I built this
2620

@@ -48,8 +42,9 @@ The utility runs the following commands:
4842

4943
- Unlink all detected PHP versions
5044
- Switch to PHP 7.4 (this is done in order to ensure that Valet works, even when attempting to use PHP 5.6)
51-
- Tell Valet to switch to a specific PHP version
45+
- Stop all php-fpm service instances
5246
- Link the desired version of PHP
47+
- Start the correct php-fpm service for the desired PHP version
5348

5449
### Want to know more?
5550

@@ -59,6 +54,8 @@ This app isn't very complicated after all. In the end, this just (conveniently)
5954

6055
## Troubleshooting
6156

57+
---
58+
6259
### Reasons for alerts at startup
6360

6461
PHP Monitor performs some integrity checks to ensure a good experience when using the app. You'll get a message telling you that PHP Monitor won't work correctly in the following scenarios:
@@ -71,12 +68,48 @@ PHP Monitor performs some integrity checks to ensure a good experience when usin
7168

7269
Follow instructions as specified in the alert in order to resolve any issues.
7370

74-
### Still seeing another PHP version (from before switching versions)?
71+
---
72+
73+
### Laravel Valet is using a different version of PHP than what is active in PHP Monitor and in my terminal!
74+
75+
If you're still seeing another version of PHP in your scripts β€” e.g. when running `phpinfo()` β€” I recommend you shut down all PHP services that are currently active. You can find out what services are active by running:
76+
77+
sudo brew services list | grep php
78+
79+
This will present to you a list of services, like so (depending on the installed versions of PHP):
7580

76-
If you're still seeing an old version of PHP in your scripts β€” e.g. when running `phpinfo()` β€” I recommend you shut down the PHP service by running:
81+
```
82+
php started root /Library/LaunchDaemons/homebrew.mxcl.php.plist
83+
84+
85+
86+
87+
88+
```
89+
90+
You'll want to make sure that **only one service is running** and that it is running **as `root`**. You can terminate a service by running:
91+
92+
sudo brew services stop {service_name}
93+
94+
So in order to disable PHP 7.3, you'd need to run:
95+
96+
sudo brew services stop [email protected]
97+
98+
If you notice that PHP FPM is running as your own user account, you can turn off the service by running:
99+
100+
brew services stop [email protected]
101+
102+
The easiest way to make sure that PHP Monitor works again is to run the following commands:
77103

78104
sudo brew services stop php
105+
sudo brew services stop [email protected]
106+
sudo brew services stop [email protected]
107+
sudo brew services stop [email protected]
108+
sudo brew services stop [email protected]
109+
sudo brew services stop [email protected]
110+
111+
Then, in PHP Monitor, select "Restart php-fpm service", which should start the service. Alternatively, you can run `sudo brew services start php@{x}` where `{x}` is your preferred version of PHP (for the latest version of PHP, you can omit `@{x}`).
79112

80-
Please note that PHP Monitor will not be able to stop this service (it doesn't run as an administrator), so you'll need to handle this yourself.
113+
---
81114

82-
You should only have to do this **once**, and then PHP Monitor should work as usual.
115+
If this software has been useful to you, star the repository so I know that the software is being used. I did not include any tracking or analytics software, so if you encounter issues, let me know via an issue.

β€Ždocs/screenshot.pngβ€Ž

302 KB
Loading

β€Žphpmon/Classes/Commands/Actions.swiftβ€Ž

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,20 @@ class Actions {
2626
return versionsOnly
2727
}
2828

29+
public static func restartPhpFpm() {
30+
let version = App.shared.currentVersion!.short
31+
if (version == Constants.LatestPhpVersion) {
32+
Shell.user.run("sudo brew services restart php")
33+
} else {
34+
Shell.user.run("sudo brew services restart php@\(version)")
35+
}
36+
}
37+
38+
public static func restartNginx()
39+
{
40+
Shell.user.run("sudo brew services restart nginx")
41+
}
42+
2943
public static func switchToPhpVersion(version: String, availableVersions: [String]) {
3044
availableVersions.forEach { (version) in
3145
// Unlink the current version
@@ -56,6 +70,11 @@ class Actions {
5670
NSWorkspace.shared.activateFileViewerSelecting(files as [URL])
5771
}
5872

73+
public static func openValetConfigFolder() {
74+
let files = [NSURL(fileURLWithPath: NSString(string: "~/.config/valet").expandingTildeInPath)];
75+
NSWorkspace.shared.activateFileViewerSelecting(files as [URL])
76+
}
77+
5978
public static func XdebugFound(_ version: String) -> Bool {
6079
let command = """
6180
grep -q 'zend_extension="xdebug.so"' /usr/local/etc/php/\(version)/php.ini; [ $? -eq 0 ] && echo "YES" || echo "NO"

β€Žphpmon/Info.plistβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
<key>LSUIElement</key>
2828
<true/>
2929
<key>NSHumanReadableCopyright</key>
30-
<string>Copyright Β© 2019 Nico Verbruggen. All rights reserved.</string>
30+
<string>Copyright Β© 2020 Nico Verbruggen. All rights reserved.</string>
3131
<key>NSMainStoryboardFile</key>
3232
<string>Main</string>
3333
<key>NSPrincipalClass</key>

β€Žphpmon/Singletons/MainMenu.swiftβ€Ž

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,21 @@ class MainMenu: NSObject, NSWindowDelegate {
5757
menu.addItem(menuItem)
5858
}
5959
menu.addItem(NSMenuItem.separator())
60+
menu.addItem(NSMenuItem(title: "Active Services", action: nil, keyEquivalent: ""))
61+
menu.addItem(NSMenuItem(title: "Restart php-fpm service", action: #selector(self.restartPhpFpm), keyEquivalent: "f"))
62+
menu.addItem(NSMenuItem(title: "Restart nginx service", action: #selector(self.restartNginx), keyEquivalent: "n"))
63+
menu.addItem(NSMenuItem.separator())
6064
}
6165
if (App.shared.busy) {
62-
menu.addItem(NSMenuItem(title: "Switching PHP versions...", action: nil, keyEquivalent: ""))
66+
menu.addItem(NSMenuItem(title: "PHP Monitor is busy...", action: nil, keyEquivalent: ""))
6367
menu.addItem(NSMenuItem.separator())
6468
}
6569
if (App.shared.currentVersion != nil) {
70+
menu.addItem(NSMenuItem(title: "Configuration", action: nil, keyEquivalent: ""))
71+
menu.addItem(NSMenuItem(title: "Valet configuration (.config/valet)", action: #selector(self.openValetConfigFolder), keyEquivalent: "v"))
6672
menu.addItem(NSMenuItem(title: "PHP configuration file (php.ini)", action: #selector(self.openActiveConfigFolder), keyEquivalent: "c"))
73+
menu.addItem(NSMenuItem.separator())
74+
menu.addItem(NSMenuItem(title: "Enabled Extensions", action: nil, keyEquivalent: ""))
6775
let xdebugFound = App.shared.currentVersion!.xdebugFound
6876
if (xdebugFound) {
6977
let xdebugOn = App.shared.currentVersion!.xdebugEnabled
@@ -127,6 +135,39 @@ class MainMenu: NSObject, NSWindowDelegate {
127135
self.update()
128136
}
129137

138+
@objc func setBusyImage() {
139+
DispatchQueue.main.async {
140+
self.setStatusBar(image: NSImage(named: NSImage.Name("StatusBarIcon"))!)
141+
}
142+
}
143+
144+
private func waitAndExecute(_ execute: @escaping () -> Void)
145+
{
146+
App.shared.busy = true
147+
self.setBusyImage()
148+
DispatchQueue.global(qos: .userInitiated).async { [unowned self] in
149+
self.update()
150+
execute()
151+
App.shared.busy = false
152+
DispatchQueue.main.async {
153+
self.updatePhpVersionInStatusBar()
154+
self.update()
155+
}
156+
}
157+
}
158+
159+
@objc public func restartPhpFpm() {
160+
self.waitAndExecute({
161+
Actions.restartPhpFpm()
162+
})
163+
}
164+
165+
@objc public func restartNginx() {
166+
self.waitAndExecute({
167+
Actions.restartNginx()
168+
})
169+
}
170+
130171
@objc public func openAbout() {
131172
NSApplication.shared.activate(ignoringOtherApps: true)
132173
NSApplication.shared.orderFrontStandardAboutPanel()
@@ -136,8 +177,12 @@ class MainMenu: NSObject, NSWindowDelegate {
136177
Actions.openPhpConfigFolder(version: App.shared.currentVersion!.short)
137178
}
138179

180+
@objc public func openValetConfigFolder() {
181+
Actions.openValetConfigFolder()
182+
}
183+
139184
@objc public func switchToPhpVersion(sender: AnyObject) {
140-
self.setStatusBar(image: NSImage(named: NSImage.Name("StatusBarIcon"))!)
185+
self.setBusyImage()
141186
let index = sender.tag!
142187
let version = App.shared.availablePhpVersions[index]
143188
App.shared.busy = true

0 commit comments

Comments
Β (0)