Skip to content

Commit f7272bb

Browse files
committed
Update readme and composer file
1 parent ec2ba91 commit f7272bb

File tree

3 files changed

+74
-75
lines changed

3 files changed

+74
-75
lines changed

README.md

Lines changed: 65 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
# PhpRunner runtime for symfony applications
22
![PHP >=8.2](https://img.shields.io/badge/PHP->=8.2-777bb3.svg?style=flat)
3-
![Symfony ^6.4|^7.0](https://img.shields.io/badge/Symfony-^7.0-374151.svg?style=flat)
3+
![Symfony ^7.0](https://img.shields.io/badge/Symfony-^7.0-374151.svg?style=flat)
44
[![Version](https://img.shields.io/github/v/tag/luzrain/phprunner-bundle?label=Version&filter=v*.*.*&sort=semver&color=374151)](../../releases)
55
[![Tests Status](https://img.shields.io/github/actions/workflow/status/luzrain/phprunner-bundle/tests.yaml?label=Tests&branch=master)](../../actions/workflows/tests.yaml)
66

77
This bundle provides a [PhpRunner](https://github.com/luzrain/phprunner) integration with Symfony framework to run your application in a highly efficient event-loop based runtime.
88

9-
> [!NOTE]
10-
> This tool is in development now
11-
129
## Getting started
1310
### Install composer packages
1411
```bash
@@ -38,16 +35,9 @@ $ bin/console config:dump-reference phprunner
3835

3936
phprunner:
4037
servers:
41-
- name: 'Symfony webserver'
38+
- name: 'Webserver'
4239
listen: http://0.0.0.0:80
4340
processes: 4
44-
45-
reload_strategy:
46-
exception:
47-
active: true
48-
49-
file_monitor:
50-
active: true
5141
```
5242
5343
### Start application
@@ -58,18 +48,24 @@ $ APP_RUNTIME=Luzrain\\PhpRunnerBundle\\Runtime php public/index.php start
5848
\* For better performance, install the _php-uv_ extension.
5949

6050
## Reload strategies
61-
Because of the asynchronous nature of the server, the workers reuse loaded resources on each request. This means that in some cases we need to restart workers.
62-
For example, after an exception is thrown, to prevent services from being in an unrecoverable state. Or every time you change the code in the IDE.
63-
There are a few restart strategies that are implemented and can be enabled or disabled depending on the environment.
64-
65-
- **exception**
66-
Reload worker each time that an exception is thrown during the request handling.
67-
- **max_requests**
68-
Reload worker on every N request to prevent memory leaks.
69-
- **file_monitor**
70-
Reload all workers each time you change the files**.
71-
- **always**
72-
Reload worker after each request.
51+
Because of the asynchronous nature of the server, the workers reuse loaded resources on each request.
52+
This means that in some cases we need to restart workers.
53+
For example, after an exception is thrown, to prevent services from being in an unrecoverable state.
54+
Or every time you change the code in the IDE in dev environment.
55+
The bundle provides several restart strategies that can be configured depending on what you need.
56+
57+
- **on_exception**
58+
Reload worker each time that an exception is thrown during the worker lifetime.
59+
- **on_each_request**
60+
Reload worker after each http request. This strategy is for debug purposes.
61+
- **on_ttl_limit**
62+
Reload worker after TTL lifiteme will be reached. Can be used to prevent memory leaks.
63+
- **on_requests_limit**
64+
Reload worker on every N request.
65+
- **on_memory_limit**
66+
Reload worker after memory usage exceeds threshold value.
67+
- **on_file_change**
68+
Reload all workers each time that monitored files are changed. **
7369

7470
** It is highly recommended to install the _php-inotify_ extension for file monitoring. Without it, monitoring will work in polling mode, which can be very cpu and disk intensive for large projects.
7571

@@ -78,60 +74,63 @@ See all available options for each strategy in the command output.
7874
$ bin/console config:dump-reference phprunner reload_strategy
7975
```
8076

77+
```yaml
78+
# config/packages/phprunner.yaml
79+
80+
phprunner:
81+
reload_strategy:
82+
on_exception:
83+
active: true
84+
85+
on_file_change:
86+
active: true
87+
```
88+
8189
## Scheduler
82-
Periodic tasks can be configured with attributes or with tags in configuration files.
83-
Schedule string can be formatted in several ways:
90+
Periodic tasks can schedule the execution of external programs as well as internal Symfony application commands.
91+
To run a Symfony command, simply type the command name without any prefixes.
92+
Schedule string can be formatted in several ways:
8493
- An integer to define the frequency as a number of seconds. Example: _60_
85-
- An ISO8601 datetime format. Example: _2023-08-01T01:00:00+08:00_
94+
- An ISO8601 datetime format. Example: _2024-02-14T018:00:00+08:00_
8695
- An ISO8601 duration format. Example: _PT1M_
8796
- A relative date format as supported by DateInterval. Example: _1 minutes_
8897
- A cron expression**. Example: _*/1 * * * *_
8998
9099
** Note that you need to install the [dragonmantank/cron-expression](https://github.com/dragonmantank/cron-expression) package if you want to use cron expressions as schedule strings
91100
92-
```php
93-
<?php
101+
```yaml
102+
# config/packages/phprunner.yaml
94103

95-
use Luzrain\PhpRunnerBundle\Attribute\AsTask;
96-
97-
/**
98-
* Attribute parameters
99-
* name: Task name
100-
* schedule: Task schedule in any format
101-
* method: method to call, __invoke by default
102-
* jitter: Maximum jitter in seconds that adds a random time offset to the schedule. Use to prevent multiple tasks from running at the same time
103-
*/
104-
#[AsTask(name: 'My scheduled task', schedule: '1 minutes')]
105-
final class TaskService
106-
{
107-
public function __invoke()
108-
{
109-
// ...
110-
}
111-
}
104+
phprunner:
105+
tasks:
106+
# Runs external program every 15 seconds
107+
- name: 'Task 1'
108+
schedule: '15 second'
109+
command: '/bin/external-program'
110+
111+
# Runs symfony command as a task every minute
112+
- name: 'Task 2'
113+
schedule: '*/1 * * * *'
114+
command: 'app:my-task-command'
112115
```
113116
114117
## Supervisor
115-
Supervisor can be configured with attributes or with tags in configuration files.
116-
Processes are kept alive and wake up if one of them dies.
118+
Supervisor can keep processes alive and wake up when one of them dies.
119+
It can also work with both external commands and internal Symfony commands.
120+
To run a Symfony command, simply type the command name without any prefixes.
117121
118-
```php
119-
<?php
122+
```yaml
123+
# config/packages/phprunner.yaml
120124

121-
use Luzrain\PhpRunnerBundle\Attribute\AsProcess;
122-
123-
/**
124-
* Attribute parameters
125-
* name: Process name
126-
* processes: number of processes
127-
* method: method to call, __invoke by default
128-
*/
129-
#[AsProcess(name: 'My worker', processes: 1)]
130-
final class ProcessService
131-
{
132-
public function __invoke()
133-
{
134-
// ...
135-
}
136-
}
125+
phprunner:
126+
processes:
127+
# Runs external program
128+
- name: 'External process'
129+
command: '/bin/external-program'
130+
count: 1
131+
132+
# Runs symfony command
133+
- name: 'Symfony command process'
134+
command: 'messenger:consume queue --time-limit=600'
135+
count: 4
137136
```

composer.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
}
1313
],
1414
"require": {
15-
"php": "^8.2",
15+
"php": ">=8.2",
1616
"ext-pcntl": "*",
1717
"ext-posix": "*",
18-
"luzrain/phprunner": "dev-master",
18+
"luzrain/phprunner": "^0.1",
1919
"psr/http-factory": "^1.0",
2020
"symfony/config": "^7.0",
2121
"symfony/dependency-injection": "^7.0",
@@ -32,7 +32,6 @@
3232
"vimeo/psalm": "^5.21"
3333
},
3434
"suggest": {
35-
"ext-uv": "For better performance",
3635
"ext-inotify": "For effective file monitoring",
3736
"dragonmantank/cron-expression": "For parse cron expressions"
3837
},

src/config/configuration.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@
141141
->defaultFalse()
142142
->end()
143143
->integerNode('ttl')
144-
->info('TTL in seconds after which the worker is reloaded')
144+
->info('TTL in seconds')
145145
->isRequired()
146146
->end()
147147
->end()
@@ -155,7 +155,7 @@
155155
->defaultFalse()
156156
->end()
157157
->integerNode('requests')
158-
->info('Maximum number of requests after which the worker is reloaded')
158+
->info('Maximum number of requests')
159159
->isRequired()
160160
->end()
161161
->integerNode('dispersion')
@@ -165,21 +165,22 @@
165165
->end()
166166
->end()
167167
->arrayNode('on_memory_limit')
168-
->info('Reload worker after memory consumption would increase N')
168+
->info('Reload worker after memory usage exceeds threshold value')
169169
->addDefaultsIfNotSet()
170170
->children()
171171
->booleanNode('active')
172172
->info('Is strategy active')
173173
->defaultFalse()
174174
->end()
175175
->integerNode('memory')
176-
->info('Memory in bytes after increase that the worker is reloaded')
176+
->info('Threshold memory consumption in bytes')
177+
->min(1024)
177178
->isRequired()
178179
->end()
179180
->end()
180181
->end()
181182
->arrayNode('on_file_change')
182-
->info('Reload all workers each time that files is change')
183+
->info('Reload all workers each time that monitored files are changed')
183184
->addDefaultsIfNotSet()
184185
->children()
185186
->booleanNode('active')
@@ -195,7 +196,7 @@
195196
])
196197
->end()
197198
->arrayNode('file_pattern')
198-
->info('Monitored file patterns')
199+
->info('Monitored files patterns')
199200
->prototype('scalar')->end()
200201
->defaultValue([
201202
'*.php',

0 commit comments

Comments
 (0)