|
5 | 5 | // [FrankenPHP app server]: https://frankenphp.dev |
6 | 6 | package frankenphp |
7 | 7 |
|
| 8 | +//go:generate rm -Rf C-Thread-Pool/ |
8 | 9 | //go:generate git clone --branch=feat/mac-os-compat --depth=1 git@github.com:dunglas/C-Thread-Pool.git |
9 | | -//go:generate rm -rf C-Thread-Pool/.git C-Thread-Pool/.circleci C-Thread-Pool/docs C-Thread-Pool/tests |
| 10 | +//go:generate rm -Rf C-Thread-Pool/.git C-Thread-Pool/.circleci C-Thread-Pool/docs C-Thread-Pool/tests |
10 | 11 |
|
11 | 12 | // #cgo CFLAGS: -Wall |
12 | 13 | // #cgo CFLAGS: -I/usr/local/include/php -I/usr/local/include/php/Zend -I/usr/local/include/php/TSRM -I/usr/local/include/php/main |
|
45 | 46 | AlreaydStartedError = errors.New("FrankenPHP is already started") |
46 | 47 | InvalidPHPVersionError = errors.New("FrankenPHP is only compatible with PHP 8.2+") |
47 | 48 | ZendSignalsError = errors.New("Zend Signals are enabled, recompile PHP with --disable-zend-signals") |
| 49 | + NotEnoughThreads = errors.New("the number of threads must be superior to the number of workers") |
48 | 50 | MainThreadCreationError = errors.New("error creating the main thread") |
49 | 51 | RequestContextCreationError = errors.New("error during request context creation") |
50 | 52 | RequestStartupError = errors.New("error during PHP request startup") |
@@ -221,16 +223,18 @@ func Init(options ...Option) error { |
221 | 223 | opt.workers[i].num = numCPU |
222 | 224 | } |
223 | 225 |
|
224 | | - numWorkers += w.num |
| 226 | + numWorkers += opt.workers[i].num |
225 | 227 | } |
226 | 228 |
|
227 | 229 | if opt.numThreads <= 0 { |
228 | 230 | if numWorkers >= numCPU { |
229 | | - // Keep a free thread to handle requests not handled by a worker |
230 | | - opt.numThreads = numCPU + 1 |
| 231 | + // Start at least as many threads as workers, and keep a free thread to handle requests in non-worker mode |
| 232 | + opt.numThreads = numWorkers + 1 |
231 | 233 | } else { |
232 | 234 | opt.numThreads = numCPU |
233 | 235 | } |
| 236 | + } else if opt.numThreads <= numWorkers { |
| 237 | + return NotEnoughThreads |
234 | 238 | } |
235 | 239 |
|
236 | 240 | switch C.frankenphp_check_version() { |
|
0 commit comments