Trying to get TYPO3 to work in worker-mode
Open
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 11.3k
- Forks
- 488
- Avg merge
- 4d 10h
- Merged PRs (30d)
- 11
Description
I tried to get TYPO3 working in worker mode. I used the Custom Apps as a base.
This is what i have so far:
<?php
ignore_user_abort(true);
$classLoader = require dirname(__DIR__).'/vendor/autoload.php';
\TYPO3\CMS\Core\Core\SystemEnvironmentBuilder::run(0, \TYPO3\CMS\Core\Core\SystemEnvironmentBuilder::REQUESTTYPE_FE);
/** @var \TYPO3\CMS\Frontend\Http\Application $app */
$app = \TYPO3\CMS\Core\Core\Bootstrap::init($classLoader)->get(\TYPO3\CMS\Frontend\Http\Application::class);
// Handler outside the loop for better performance (doing less work)
$handler = static function () use ($app) {
// Called when a request is received,
// superglobals, php://input and the like are reset
$response = $app->handle(\TYPO3\CMS\Core\Http\ServerRequestFactory::fromGlobals());
$app->sendResponse($response);
};
for ($nbRequests = 0, $running = true; isset($_SERVER['MAX_REQUESTS']) && ($nbRequests < ((int)$_SERVER['MAX_REQUESTS'])) && $running; ++$nbRequests) {
$running = \frankenphp_handle_request($handler);
// What to do with the $app here?
// $app->terminate();
gc_collect_cycles();
}
// What to do with the $app here?
// $app->shutdown();
Here my questions:
- How to debug this? Like, getting actual error messages related to my worker script?
- Do i actually need
terminate();andshtudown();to do something specific? - In general, any idea what is going on here?
Output of frankenphp run -c Caddyfile --envfile .env:
2024/01/16 00:52:11.166 INFO using provided configuration {"config_file": "Caddyfile", "config_adapter": ""}
2024/01/16 00:52:11.169 WARN Caddyfile input is not formatted; run 'caddy fmt --overwrite' to fix inconsistencies {"adapter": "caddyfile", "file": "Caddyfile", "line": 19}
2024/01/16 00:52:11.171 INFO admin admin endpoint started {"address": "localhost:2019", "enforce_origin": false, "origins": ["//localhost:2019", "//[::1]:2019", "//127.0.0.1:2019"]}
2024/01/16 00:52:11.171 WARN http.auto_https server is listening only on the HTTP port, so no automatic HTTPS will be applied to this server {"server_name": "srv0", "http_port": 8787}
2024/01/16 00:52:11.171 INFO http.auto_https server is listening only on the HTTPS port but has no TLS connection policies; adding one to enable TLS {"server_name": "srv1", "https_port": 8788}
2024/01/16 00:52:11.171 INFO http.auto_https enabling automatic HTTP->HTTPS redirects {"server_name": "srv1"}
2024/01/16 00:52:11.171 INFO tls.cache.maintenance started background certificate maintenance {"cache": "0x140002e9100"}
2024/01/16 00:52:11.172 DEBUG http.auto_https adjusted config {"tls": {"automation":{"policies":[{"subjects":["localhost"]},{}]}}, "http": {"http_port":8787,"https_port":8788,"servers":{"srv0":{"listen":[":8787"],"routes":[{"handle":[{"handler":"subroute","routes":[{"handle":[{"handler":"vars","root":"public/"}]},{"handle":[{"handler":"static_response","headers":{"Location":["{http.request.uri.path}/"]},"status_code":308}],"match":[{"file":{"try_files":["{http.request.uri.path}/index.php"]},"not":[{"path":["*/"]}]}]},{"group":"group0","handle":[{"handler":"rewrite","uri":"{http.matchers.file.relative}"}],"match":[{"file":{"split_path":[".php"],"try_files":["{http.request.uri.path}","{http.request.uri.path}/index.php","/index.php"]},"not":[{"path":["/typo3/*","/.well-known/*","/_assets/*","/favicon.ico"]}]}]},{"group":"group0","handle":[{"handler":"rewrite","uri":"{http.matchers.file.relative}"}],"match":[{"file":{"split_path":[".php"],"try_files":["{http.request.uri.path}","{http.request.uri.path}/index.php","/typo3/index.php"]},"not":[{"path":["/typo3/install.php","/.well-known/*","/_assets/*","/favicon.ico"]}],"path":["/typo3/*"]}]},{"handle":[{"encodings":{"gzip":{},"zstd":{}},"handler":"encode","prefer":["zstd","gzip"]},{"anonymous":true,"demo":true,"handler":"mercure","publisher_jwt":{"alg":"{env.MERCURE_PUBLISHER_JWT_ALG}","key":"{env.MERCURE_PUBLISHER_JWT_KEY}"},"subscriber_jwt":{"alg":"{env.MERCURE_SUBSCRIBER_JWT_ALG}","key":"{env.MERCURE_SUBSCRIBER_JWT_KEY}"},"subscriptions":true,"transport_url":"bolt://mercure-database.db"}]},{"handle":[{"handler":"static_response","headers":{"Location":["{http.request.orig_uri.path}/"]},"status_code":308}],"match":[{"file":{"try_files":["{http.request.uri.path}/index.php"]},"not":[{"path":["*/"]}]}]},{"handle":[{"handler":"rewrite","uri":"{http.matchers.file.relative}"}],"match":[{"file":{"split_path":[".php"],"try_files":["{http.request.uri.path}","{http.request.uri.path}/index.php","index.php"]}}]},{"handle":[{"handler":"php","split_path":[".php"]}],"match":[{"path":["*.php"]}]},{"handle":[{"handler":"file_server"}]}]}],"terminal":true},{},{}],"automatic_https":{"disable":true},"logs":{"logger_names":{"localhost":"log0"}},"metrics":{}},"srv1":{"listen":[":8788"],"routes":[{"handle":[{"handler":"subroute","routes":[{"handle":[{"handler":"vars","root":"public/"}]},{"handle":[{"handler":"static_response","headers":{"Location":["{http.request.uri.path}/"]},"status_code":308}],"match":[{"file":{"try_files":["{http.request.uri.path}/index.php"]},"not":[{"path":["*/"]}]}]},{"group":"group1","handle":[{"handler":"rewrite","uri":"{http.matchers.file.relative}"}],"match":[{"file":{"split_path":[".php"],"try_files":["{http.request.uri.path}","{http.request.uri.path}/index.php","/index.php"]},"not":[{"path":["/typo3/*","/.well-known/*","/_assets/*","/favicon.ico"]}]}]},{"group":"group1","handle":[{"handler":"rewrite","uri":"{http.matchers.file.relative}"}],"match":[{"file":{"split_path":[".php"],"try_files":["{http.request.uri.path}","{http.request.uri.path}/index.php","/typo3/index.php"]},"not":[{"path":["/typo3/install.php","/.well-known/*","/_assets/*","/favicon.ico"]}],"path":["/typo3/*"]}]},{"handle":[{"encodings":{"gzip":{},"zstd":{}},"handler":"encode","prefer":["zstd","gzip"]},{"anonymous":true,"demo":true,"handler":"mercure","publisher_jwt":{"alg":"{env.MERCURE_PUBLISHER_JWT_ALG}","key":"{env.MERCURE_PUBLISHER_JWT_KEY}"},"subscriber_jwt":{"alg":"{env.MERCURE_SUBSCRIBER_JWT_ALG}","key":"{env.MERCURE_SUBSCRIBER_JWT_KEY}"},"subscriptions":true,"transport_url":"bolt://mercure-database.db"}]},{"handle":[{"handler":"static_response","headers":{"Location":["{http.request.orig_uri.path}/"]},"status_code":308}],"match":[{"file":{"try_files":["{http.request.uri.path}/index.php"]},"not":[{"path":["*/"]}]}]},{"handle":[{"handler":"rewrite","uri":"{http.matchers.file.relative}"}],"match":[{"file":{"split_path":[".php"],"try_files":["{http.request.uri.path}","{http.request.uri.path}/index.php","index.php"]}}]},{"handle":[{"handler":"php","split_path":[".php"]}],"match":[{"path":["*.php"]}]},{"handle":[{"handler":"file_server"}]}]}],"terminal":true}],"tls_connection_policies":[{}],"automatic_https":{},"logs":{"logger_names":{"localhost":"log0"}},"metrics":{}}}}}
2024/01/16 00:52:11.179 DEBUG starting {"worker": "/Users/jochen/Development/franky/public/worker.php"}
2024/01/16 00:52:11.179 DEBUG starting {"worker": "/Users/jochen/Development/franky/public/worker.php"}
2024/01/16 00:52:11.179 DEBUG starting {"worker": "/Users/jochen/Development/franky/public/worker.php"}
2024/01/16 00:52:11.179 DEBUG starting {"worker": "/Users/jochen/Development/franky/public/worker.php"}
2024/01/16 00:52:11.179 DEBUG starting {"worker": "/Users/jochen/Development/franky/public/worker.php"}
.....
2024/01/16 00:52:13.455 INFO restarting {"worker": "/Users/jochen/Development/franky/public/worker.php"}
2024/01/16 00:52:13.455 DEBUG starting {"worker": "/Users/jochen/Development/franky/public/worker.php"}
2024/01/16 00:52:13.474 INFO restarting {"worker": "/Users/jochen/Development/franky/public/worker.php"}
2024/01/16 00:52:13.474 DEBUG starting {"worker": "/Users/jochen/Development/franky/public/worker.php"}
2024/01/16 00:52:13.479 INFO restarting {"worker": "/Users/jochen/Development/franky/public/worker.php"}
2024/01/16 00:52:13.479 DEBUG starting {"worker": "/Users/jochen/Development/franky/public/worker.php"}
2024/01/16 00:52:13.479 INFO restarting {"worker": "/Users/jochen/Development/franky/public/worker.php"}
2024/01/16 00:52:13.479 DEBUG starting {"worker": "/Users/jochen/Development/franky/public/worker.php"}
2024/01/16 00:52:13.558 INFO restarting {"worker": "/Users/jochen/Development/franky/public/worker.php"}
-----> KEEPS RESTARTING ALL DAY
Here is my playground project:
https://gitlab.knallimall.org/ochorocho/franky
Thank you. :-)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked playground's public/worker.php and Caddyfile, then run frankenphp run -c Caddyfile --envfile .env while inspecting the worker restart output. Compare the worker-mode setup with the referenced Custom Apps documentation; done means TYPO3 starts in worker mode, serves requests, and no longer repeatedly restarts.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100