Skip to content

Commit e263970

Browse files
committed
Merge branch 'feat/configurable-watch-paths'
2 parents 753bf7d + 4e8ccb8 commit e263970

File tree

4 files changed

+65
-42
lines changed

4 files changed

+65
-42
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ Before using this feature, you should ensure that [Node](https://nodejs.org) is
132132
npm install --save-dev chokidar
133133
```
134134

135+
You may configure the directories and files that should be watched using the `watch` configuration option within your application's `config/octane.php` configuration file.
136+
135137
#### Specifying The Worker Count
136138

137139
By default, Octane will start an application request worker for each CPU core provided by your machine. However, you may manually specify how many workers you would like to start using the `--workers` option when invoking the `octane:start` command:

bin/file-watcher.js

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,10 @@
11
const chokidar = require('chokidar');
22

3-
const basePath = process.argv[2];
3+
const paths = JSON.parse(process.argv[2]);
44

5-
const watcher = chokidar.watch(
6-
[
7-
basePath + '/app',
8-
basePath + '/bootstrap',
9-
basePath + '/config',
10-
basePath + '/database',
11-
basePath + '/public',
12-
basePath + '/resources',
13-
basePath + '/routes',
14-
basePath + '/composer.lock',
15-
basePath + '/.env',
16-
],
17-
{
18-
ignoreInitial: true,
19-
}
20-
);
5+
const watcher = chokidar.watch(paths, {
6+
ignoreInitial: true,
7+
});
218

229
watcher
2310
.on('add', () => console.log('File added...'))

config/octane.php

Lines changed: 49 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -122,30 +122,6 @@
122122
//
123123
],
124124

125-
/*
126-
|--------------------------------------------------------------------------
127-
| Garbage Collection Threshold
128-
|--------------------------------------------------------------------------
129-
|
130-
| When executing long-lived PHP scripts such as Octane, memory can build
131-
| up before being cleared by PHP. You can force Octane to run garbage
132-
| collection if your application consumes this amount of megabytes.
133-
|
134-
*/
135-
136-
'garbage' => 50,
137-
138-
/*
139-
|--------------------------------------------------------------------------
140-
| Maximum Execution Time
141-
|--------------------------------------------------------------------------
142-
|
143-
| (info) 0 means no maximum limit
144-
|
145-
*/
146-
147-
'max_execution_time' => 30,
148-
149125
/*
150126
|--------------------------------------------------------------------------
151127
| Octane Cache Table
@@ -180,4 +156,53 @@
180156
],
181157
],
182158

159+
/*
160+
|--------------------------------------------------------------------------
161+
| File Watching
162+
|--------------------------------------------------------------------------
163+
|
164+
| The following list of files and directories will be watched when using
165+
| the --watch option offered by Octane. If any of the directories and
166+
| files are changed, Octane will automatically reload your workers.
167+
|
168+
*/
169+
170+
'watch' => [
171+
'app',
172+
'bootstrap',
173+
'config',
174+
'database',
175+
'public',
176+
'resources',
177+
'routes',
178+
'composer.lock',
179+
'.env',
180+
],
181+
182+
/*
183+
|--------------------------------------------------------------------------
184+
| Garbage Collection Threshold
185+
|--------------------------------------------------------------------------
186+
|
187+
| When executing long-lived PHP scripts such as Octane, memory can build
188+
| up before being cleared by PHP. You can force Octane to run garbage
189+
| collection if your application consumes this amount of megabytes.
190+
|
191+
*/
192+
193+
'garbage' => 50,
194+
195+
/*
196+
|--------------------------------------------------------------------------
197+
| Maximum Execution Time
198+
|--------------------------------------------------------------------------
199+
|
200+
| The following setting configures the maximum execution time for requests
201+
| being handled by Octane. You may set this value to 0 to indicate that
202+
| there isn't a specific time limit on Octane request execution time.
203+
|
204+
*/
205+
206+
'max_execution_time' => 30,
207+
183208
];

src/Commands/Concerns/InteractsWithServers.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Laravel\Octane\Commands\Concerns;
44

5+
use InvalidArgumentException;
56
use Laravel\Octane\Exceptions\ServerShutdownException;
67
use Symfony\Component\Process\ExecutableFinder;
78
use Symfony\Component\Process\Process;
@@ -90,8 +91,16 @@ public function __call($method, $parameters)
9091
};
9192
}
9293

94+
if (empty($paths = config('octane.watch'))) {
95+
throw new InvalidArgumentException(
96+
'List of directories/files to watch not found. Please update your "config/octane.php" configuration file.',
97+
);
98+
}
99+
93100
return tap(new Process([
94-
(new ExecutableFinder)->find('node'), 'file-watcher.js', base_path(),
101+
(new ExecutableFinder)->find('node'),
102+
'file-watcher.js',
103+
json_encode(collect(config('octane.watch'))->map(fn ($path) => base_path($path))),
95104
], realpath(__DIR__.'/../../../bin'), null, null, null))->start();
96105
}
97106

0 commit comments

Comments
 (0)