You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.adoc
+8-5Lines changed: 8 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -38,12 +38,13 @@ PHP-LRPM uses exponential backoff when attempting to restart a process; some pro
38
38
39
39
== Non-goals
40
40
41
-
Currently LRPM is not intended to run as PID 1, nor was it tested in this role.
41
+
Currently, LRPM is not intended to run as PID 1, nor was it tested in this role.
42
42
43
43
== Usage
44
44
45
-
1. Implement the `ConfigurationSource`. This interface exposes a public method `loadConfiguration()`, that returns an associative array containing the configuration for all the workers (see details below).
46
-
2. Implement the `Worker`. This interface exposes two public methods, `start()` and `cycle()`. The child process will call `start()`, passing the worker configuration as an argument, and then enter an endless loop, where it calls `cycle()`, and then checks for a shutdown condition (usually, the termination of the LRPM supervisor process). Backoff should be implemented at the end of the `cycle()` method, as we dispatch signal handlers right after `cycle()` returns. Be careful not to run a tight loop at times when cycles are not doing actual work!
45
+
1. Implement one or more `Worker` classes. This interface exposes two public methods, `start()` and `cycle()`. The child process will call `start()`, passing the worker configuration as an argument, and then enter an endless loop, where it calls `cycle()`, and then checks for a shutdown condition (usually, the termination of the LRPM supervisor process). Backoff should be implemented at the end of the `cycle()` method, as we dispatch signal handlers right after `cycle()` returns. Be careful not to run a tight loop at times when cycles are not doing actual work!
46
+
2. Implement the `ConfigurationSource` class. This interface exposes a public method `loadConfiguration()`, that returns an associative array containing the configuration for all the workers (see example and full documentation in the `Job configuration` subsection).
47
+
3. Run `bin/rlpm` with your configuration class as an argument, e.g. `bin/rlpm '\MyNamespace\MyConfigurationSource'`
47
48
48
49
=== Job configuration
49
50
@@ -116,9 +117,11 @@ Worker process installs default signal handlers for SIGTERM and SIGINT. Signal h
116
117
117
118
You can implement and install your own signal handlers inside your Worker implementation, but make sure that your Worker process shuts down cleanly after receiving SIGTERM, otherwise the LRPM supervisor will consider it unresponsive and follow up with a SIGKILL.
118
119
119
-
=== Misc caveats
120
+
=== Implementing a custom entry point
120
121
121
-
Be aware that code in your entry point will run in the supervisor (parent) process, while your `Worker` classes will run in child processes. The entry point should do no more than set up the autoloader and run the `ProcessManager`. Sharing open sockets between parent and children through `fork(2)` is not safe. Worker processes should connect to wherever they need to connect to only after they have been spawned.
122
+
If you need to implement a custom entry point for LRPM, be aware that the code in your custom entry point will run in the supervisor (parent) process, while your `Worker` classes will run in child processes `fork(2)`-ed from the supervisor. The entry point should do no more than set up the autoloader and run the `ProcessManager`. Any open file descriptors apart from stdin/stdout/stderr should be closed before entering the event loop (`ProcessManager->run()`). Sharing open sockets between parent and children through `fork(2)` is not safe! Worker processes should connect to wherever they need to connect to only after they have been spawned.
123
+
124
+
If unsure, use the provided `bin/lrpm` entry point.
Copy file name to clipboardExpand all lines: README.in.adoc
+8-5Lines changed: 8 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -38,12 +38,13 @@ PHP-LRPM uses exponential backoff when attempting to restart a process; some pro
38
38
39
39
== Non-goals
40
40
41
-
Currently LRPM is not intended to run as PID 1, nor was it tested in this role.
41
+
Currently, LRPM is not intended to run as PID 1, nor was it tested in this role.
42
42
43
43
== Usage
44
44
45
-
1. Implement the `ConfigurationSource`. This interface exposes a public method `loadConfiguration()`, that returns an associative array containing the configuration for all the workers (see details below).
46
-
2. Implement the `Worker`. This interface exposes two public methods, `start()` and `cycle()`. The child process will call `start()`, passing the worker configuration as an argument, and then enter an endless loop, where it calls `cycle()`, and then checks for a shutdown condition (usually, the termination of the LRPM supervisor process). Backoff should be implemented at the end of the `cycle()` method, as we dispatch signal handlers right after `cycle()` returns. Be careful not to run a tight loop at times when cycles are not doing actual work!
45
+
1. Implement one or more `Worker` classes. This interface exposes two public methods, `start()` and `cycle()`. The child process will call `start()`, passing the worker configuration as an argument, and then enter an endless loop, where it calls `cycle()`, and then checks for a shutdown condition (usually, the termination of the LRPM supervisor process). Backoff should be implemented at the end of the `cycle()` method, as we dispatch signal handlers right after `cycle()` returns. Be careful not to run a tight loop at times when cycles are not doing actual work!
46
+
2. Implement the `ConfigurationSource` class. This interface exposes a public method `loadConfiguration()`, that returns an associative array containing the configuration for all the workers (see example and full documentation in the `Job configuration` subsection).
47
+
3. Run `bin/rlpm` with your configuration class as an argument, e.g. `bin/rlpm '\MyNamespace\MyConfigurationSource'`
47
48
48
49
=== Job configuration
49
50
@@ -79,9 +80,11 @@ Worker process installs default signal handlers for SIGTERM and SIGINT. Signal h
79
80
80
81
You can implement and install your own signal handlers inside your Worker implementation, but make sure that your Worker process shuts down cleanly after receiving SIGTERM, otherwise the LRPM supervisor will consider it unresponsive and follow up with a SIGKILL.
81
82
82
-
=== Misc caveats
83
+
=== Implementing a custom entry point
83
84
84
-
Be aware that code in your entry point will run in the supervisor (parent) process, while your `Worker` classes will run in child processes. The entry point should do no more than set up the autoloader and run the `ProcessManager`. Sharing open sockets between parent and children through `fork(2)` is not safe. Worker processes should connect to wherever they need to connect to only after they have been spawned.
85
+
If you need to implement a custom entry point for LRPM, be aware that the code in your custom entry point will run in the supervisor (parent) process, while your `Worker` classes will run in child processes `fork(2)`-ed from the supervisor. The entry point should do no more than set up the autoloader and run the `ProcessManager`. Any open file descriptors apart from stdin/stdout/stderr should be closed before entering the event loop (`ProcessManager->run()`). Sharing open sockets between parent and children through `fork(2)` is not safe! Worker processes should connect to wherever they need to connect to only after they have been spawned.
86
+
87
+
If unsure, use the provided `bin/lrpm` entry point.
0 commit comments