-
-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Provide a way to operate over original swoole server instance #44
Comments
Can you indicate how you would be using this in your own code, exactly? I only defined that particular constant so that we could internally ensure that the mode provided via configuration is valid, which is something that can be done easily in userland already (e.g., |
I would like to perform some actions with the original server instance. (in particular, inject https://github.com/upscalesoftware/swoole-newrelic). In order to achieve this, I am extending
Unfortunately, it doesn't work out because of private constants, they are not available in the child class and it leads to errors :( P.S. There are several more issues like that, I will create another issue if we would agree on this one :) |
Where are you injecting? I assume potentially an event listener? If you're using mezzio-swoole v3, you likely will want to do this via our new event system, which ties into all the workflow events of the Swoole HTTP server, and which you can do without needing to change the factory (see the events and listeners documentation). Alternately, if you are trying to add config settings or otherwise manipulate the instance, potentially try using delegator factories. |
Unfortunately, this cannot be bootstrapped after the server has been started :( In the end, to achieve my goals, I only was able to put the code in the Between The problem is that to use this library, I have to have server not started but Unfortunately, this class is also not really extendable because of the private properties that force you to duplicate basically everything.
UPD:
|
Please read the documentation - you can add listeners to the various Swoole HTTP Server by instead adding listeners to the event classes found under In this case, if you want it to run via the Swoole HTTP Server 'request' event, and want your listener to trigger first, you'd add configuration like this: use Laminas\Stdlib\ArrayUtils\MergeReplaceKey;
use Mezzio\Swoole\Event;
return [
'mezzio-swoole' => [
'swoole-http-server' => [
'listeners' => [
Event\RequestEvent:class => new MergeReplaceKey([
YourListenerGoesHere::class, // you can also do a class instance here, but your config will no longer be cacheable
Event\StaticResourceRequestListener::class,
Event\RequestHandlerRequestListener::class,
]),
],
],
],
]; Basically, you should NEVER attach directly to the Swoole HTTP Server lifecycle events; attach listeners to the internal dispatcher instead, as it allows you to compose multiple listeners safely. |
The problem, why I cannot use Event/Listeners is the fact, that I want to measure the time, that request has taken. I tried to achieve it by having Listener before and after RequestHandlerRequestListener but after the response is being sent, nothing is executed. so, once again, |
Thanks! |
I would be happy to see protected const in that class as by extending the class with private const I am forced to define it in my own and they are not different to the default one.
mezzio-swoole/src/HttpServerFactory.php
Line 39 in 5c9b0c9
I am extending it to perform some code before the swoole server starts
The text was updated successfully, but these errors were encountered: