Skip to content

Commit 17cb197

Browse files
committed
feat(franken): add configuration and guide frankenphp.md
1 parent 14c919b commit 17cb197

File tree

6 files changed

+69
-36
lines changed

6 files changed

+69
-36
lines changed

.env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# https://symfony.com/doc/current/best_practices.html#use-environment-variables-for-infrastructure-configuration
1616

1717
###> symfony/framework-bundle ###
18-
APP_ENV=prod
18+
APP_ENV=local
1919
APP_SECRET=2ca64f8d83b9e89f5f19d672841d6bb8
2020
#TRUSTED_PROXIES=127.0.0.0/8,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16
2121
#TRUSTED_HOSTS='^(localhost|example\.com)$'

README.md

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -358,17 +358,6 @@ for detailed autoloader optimization guidelines and best practices.
358358
| Franken Metrics | http://localhost:2019/metrics | Caddy/FrankenPHP metrics (non-worker) |
359359
| Worker Metrics | http://localhost:2020/metrics | Caddy/FrankenPHP metrics (worker) |
360360

361-
## Grafana Dashboard
362-
363-
A detailed PHP-FPM and OPcache monitoring dashboard is available in Grafana. It includes:
364-
365-
- PHP-FPM health, queue, and process metrics
366-
- Request rate, duration, and memory usage
367-
- OPcache hit ratio, memory, and script cache stats
368-
- JIT and interned strings monitoring
369-
- Alerts and color-coded panels for quick health checks
370-
371-
**See [`grafana-dashboard.md`](grafana-dashboard.md) for a full description of all panels and dashboard features.**
372361

373362
## FrankenPHP Configuration
374363

@@ -382,4 +371,16 @@ comparison and monitoring.
382371
- Caddy configuration and environment variables
383372
- Performance testing and monitoring
384373
- Troubleshooting guide
385-
- Resource optimization guidelines
374+
- Resource optimization guidelines
375+
376+
## Grafana Dashboard
377+
378+
A detailed PHP-FPM and OPcache monitoring dashboard is available in Grafana. It includes:
379+
380+
- PHP-FPM health, queue, and process metrics
381+
- Request rate, duration, and memory usage
382+
- OPcache hit ratio, memory, and script cache stats
383+
- JIT and interned strings monitoring
384+
- Alerts and color-coded panels for quick health checks
385+
386+
**See [`grafana-dashboard.md`](grafana-dashboard.md) for a full description of all panels and dashboard features.**

docker/Caddyfile

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@
88
max_threads auto # Keep stable, no dynamic scaling
99

1010
worker {
11-
watch
12-
11+
# watch
1312
file ./public/index.php
1413
num 16 # 2 workers per CPU core (8 cores * 2) - optimal balance
1514
}
1615

17-
php_ini {
18-
opcache.enable 0
19-
opcache.validate_timestamps 1
20-
}
16+
# php_ini {
17+
# opcache.preload ""
18+
# opcache.revalidate_freq 0
19+
# opcache.validate_timestamps 1
20+
# }
2121
}
2222
}
2323

238 KB
Loading

frankenphp.md

Lines changed: 47 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,21 @@ the Caddyfile:
129129

130130
open ./docker/Caddyfile file
131131

132+
133+
uncomment
134+
135+
```bash
136+
# watch
137+
138+
# php_ini {
139+
# opcache.preload ""
140+
# opcache.revalidate_freq 0
141+
# opcache.validate_timestamps 1
142+
# }
143+
```
144+
145+
so it will looks like this
146+
132147
```caddyfile
133148
frankenphp {
134149
num_threads 20 # Optimal: 16 workers + 4 handling threads
@@ -140,10 +155,19 @@ open ./docker/Caddyfile file
140155
file ./public/index.php
141156
num 16 # 2 workers per CPU core (8 cores * 2) - optimal balance
142157
}
158+
159+
php_ini opcache.preload ""
160+
php_ini opcache.revalidate_freq 0
161+
php_ini opcache.validate_timestamps 1
143162
}
144163
```
145164

146-
uncomment `# watch`
165+
why ?
166+
167+
watch → FrankenPHP auto-reloads when files change
168+
preload → Load files once; changes NOT detected
169+
revalidate_freq → How often to check files for changes
170+
validate_timestamps → Whether to check changes at all
147171

148172
go to terminal
149173

@@ -171,32 +195,39 @@ if you notice that we have format issue at the file we can run
171195
frankenphp fmt --overwrite --config=/etc/frankenphp/Caddyfile
172196
```
173197

174-
and reload the config
198+
if you don't faced that issue then just continue command below
175199

176200
```bash
177201
frankenphp reload --config=/etc/frankenphp/Caddyfile
178202
```
179203

180-
Go to http://localhost:8081/, if you reload it will hard reload the browser
181-
182-
### Important Considerations
204+
Go to http://localhost:8081/en/blog/, if you reload it will hard reload the browser
183205

184-
- **Performance Impact**: File watching uses system resources (inotify on Linux)
185-
- **Production Warning**: Always disable `watch` in production for stability
186-
- **Large Projects**: Watching many files can impact performance
206+
now let's open file ./src/Controller/BlogController.php
187207

188-
**Production Best Practice:**
208+
and uncommented
189209

190-
```caddyfile
191-
frankenphp {
192-
worker {
193-
file ./public/index.php
194-
# watch # Commented out for production
195-
num 8 # Increase workers instead
196-
}
210+
```php
211+
public function index(Request $request, int $page, string $_format, PostRepository $posts, TagRepository $tags): Response
212+
{
213+
phpinfo();
214+
215+
... another code
197216
}
198217
```
199218

219+
then Go to http://localhost:8081/en/blog/ again, we notice that phpinfo page is render
220+
221+
![img.png](docs/images/franken-worker-controller-watch.png)
222+
223+
so now everytime you make changes on the php, twig files it will reflect on the browser
224+
225+
### Important Considerations
226+
227+
- **Performance Impact**: File watching uses system resources
228+
- **Production Warning**: Always disable `watch` in production for stability
229+
- **Large Projects**: Watching many files can impact performance
230+
200231
### Worker Metrics
201232

202233
When `metrics` is enabled, worker information is exposed at the metrics endpoint:

src/Controller/BlogController.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ final class BlogController extends AbstractController
5151
#[Cache(smaxage: 10)]
5252
public function index(Request $request, int $page, string $_format, PostRepository $posts, TagRepository $tags): Response
5353
{
54-
dump('FF');
54+
// phpinfo();
55+
5556
$tag = null;
5657

5758
if ($request->query->has('tag')) {

0 commit comments

Comments
 (0)