Commit 947ed76
authored
[CLI] Explore spawning new OS processes in CLI spawnProcess (#3001)
## Motivation
This PR changes the Playground CLI so that every PHP subprocess spawned
by another PHP instance (e.g. `proc_open('php -v')`) is started in a
separate OS process.
When the sandboxed spawn handler detects a PHP subprocess request, it
now creates an entirely new Node.js worker thread running. Any file
locks acquired by the subprocess will properly conflict with the
parent's locks.
Before this PR two PHP instances running in the same OS process could
acquire overlapping OS-level locks (via `fcntl()` and `LockFileEx()`).
## Implementation
The way I'm augmenting `sandboxedSpawnHandlerFactory` calls in this PR
is somewhat convoluted. I'd like to revisit it once we finish the
OS-locks-related refactoring of the CLI code.
The `sandboxedSpawnHandlerFactory` now accepts a callback that creates a
new PHP worker. When a PHP subprocess is requested via `proc_open()`,
the CLI:
1. Spawns a new Node.js worker thread via `spawnWorkerThread('v1')`
2. Boots a fresh PHP runtime in that worker using `bootWorker()`
3. Connects the subprocess I/O streams to the parent
4. Terminates the worker when the subprocess exits
The key change is in `worker-thread-v1.ts` where `createPHPWorker()` now
spawns an entirely new OS process instead of reusing the existing PHP
process manager's pool.
## Follow-up work
* Refactor PlaygroundCliBlueprintV2Worker
* Refactor `@php-wasm/cli`
* Limit PHPProcessManager to one PHP instance per worker even for
request handling
* Get rid of `PHPProcessManager` usage in CLI workers1 parent 2f70805 commit 947ed76
File tree
7 files changed
+196
-126
lines changed- packages
- php-wasm
- node/src/test
- universal/src/lib
- playground
- cli/src
- blueprints-v1
- wordpress/src
7 files changed
+196
-126
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1850 | 1850 | | |
1851 | 1851 | | |
1852 | 1852 | | |
1853 | | - | |
| 1853 | + | |
| 1854 | + | |
| 1855 | + | |
| 1856 | + | |
| 1857 | + | |
1854 | 1858 | | |
1855 | 1859 | | |
1856 | 1860 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1180 | 1180 | | |
1181 | 1181 | | |
1182 | 1182 | | |
1183 | | - | |
| 1183 | + | |
| 1184 | + | |
| 1185 | + | |
| 1186 | + | |
| 1187 | + | |
1184 | 1188 | | |
1185 | 1189 | | |
1186 | 1190 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
88 | 88 | | |
89 | 89 | | |
90 | 90 | | |
| 91 | + | |
Lines changed: 11 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
3 | 5 | | |
4 | 6 | | |
5 | 7 | | |
| |||
12 | 14 | | |
13 | 15 | | |
14 | 16 | | |
15 | | - | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
16 | 21 | | |
17 | 22 | | |
18 | 23 | | |
| |||
63 | 68 | | |
64 | 69 | | |
65 | 70 | | |
66 | | - | |
67 | | - | |
68 | | - | |
| 71 | + | |
69 | 72 | | |
70 | 73 | | |
71 | 74 | | |
72 | | - | |
| 75 | + | |
73 | 76 | | |
74 | 77 | | |
75 | | - | |
| 78 | + | |
76 | 79 | | |
77 | 80 | | |
78 | 81 | | |
| |||
105 | 108 | | |
106 | 109 | | |
107 | 110 | | |
108 | | - | |
| 111 | + | |
109 | 112 | | |
110 | 113 | | |
111 | 114 | | |
| |||
Lines changed: 122 additions & 85 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| 24 | + | |
| 25 | + | |
24 | 26 | | |
25 | 27 | | |
26 | 28 | | |
| |||
122 | 124 | | |
123 | 125 | | |
124 | 126 | | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | | - | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | | - | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | | - | |
137 | | - | |
138 | | - | |
139 | | - | |
140 | | - | |
141 | | - | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
142 | 138 | | |
143 | 139 | | |
144 | 140 | | |
145 | 141 | | |
146 | 142 | | |
147 | | - | |
148 | | - | |
149 | | - | |
150 | 143 | | |
151 | 144 | | |
152 | 145 | | |
| |||
157 | 150 | | |
158 | 151 | | |
159 | 152 | | |
160 | | - | |
161 | | - | |
162 | | - | |
163 | | - | |
164 | | - | |
165 | | - | |
166 | | - | |
167 | | - | |
168 | | - | |
169 | | - | |
170 | | - | |
171 | | - | |
172 | | - | |
173 | | - | |
174 | | - | |
175 | | - | |
176 | | - | |
177 | | - | |
178 | | - | |
179 | | - | |
180 | | - | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
181 | 157 | | |
182 | 158 | | |
183 | 159 | | |
| |||
203 | 179 | | |
204 | 180 | | |
205 | 181 | | |
206 | | - | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
207 | 186 | | |
208 | 187 | | |
209 | 188 | | |
| |||
230 | 209 | | |
231 | 210 | | |
232 | 211 | | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
233 | 216 | | |
234 | 217 | | |
235 | 218 | | |
236 | 219 | | |
237 | | - | |
238 | | - | |
239 | | - | |
240 | | - | |
241 | | - | |
242 | | - | |
243 | | - | |
244 | | - | |
245 | | - | |
246 | | - | |
247 | | - | |
248 | | - | |
| 220 | + | |
249 | 221 | | |
250 | 222 | | |
251 | 223 | | |
252 | 224 | | |
253 | 225 | | |
254 | | - | |
255 | | - | |
256 | | - | |
257 | 226 | | |
258 | 227 | | |
259 | | - | |
260 | | - | |
261 | | - | |
262 | | - | |
263 | | - | |
264 | | - | |
265 | | - | |
266 | | - | |
267 | | - | |
268 | | - | |
269 | | - | |
270 | | - | |
271 | | - | |
272 | | - | |
273 | | - | |
274 | | - | |
275 | | - | |
276 | | - | |
277 | | - | |
278 | | - | |
279 | | - | |
280 | | - | |
281 | | - | |
282 | | - | |
283 | | - | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
284 | 233 | | |
285 | | - | |
286 | | - | |
| 234 | + | |
| 235 | + | |
287 | 236 | | |
288 | 237 | | |
289 | 238 | | |
290 | | - | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
291 | 243 | | |
292 | 244 | | |
293 | 245 | | |
| |||
307 | 259 | | |
308 | 260 | | |
309 | 261 | | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
310 | 347 | | |
311 | 348 | | |
312 | 349 | | |
| |||
0 commit comments