Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

reloading#5354

Answeredbyhenrywood
rbro asked this question inQ&A
Jun 2, 2024· 3 comments· 3 replies
Discussion options

I am running a swoole http server and trying to figure out how reloading works. Is there a complete example somewhere of how hot reloading works? I'm used to php-fpm where I can edit any file and refresh in my browser to see the changes, and I'm trying to figure out how close I can get to simulating that with swoole.

Thanks for your help.

Ryan

You must be logged in to vote

Maybe try something like:

$this->server = new Swoole\Http\Server("127.0.0.1", 9501, SWOOLE_BASE);

$this->server->set([
... other options here ...
'worker_num' => 2, // The number of worker processes to start
]);

If that does not work, try:

$this->server = new Swoole\Http\Server("127.0.0.1", 9501, SWOOLE_PROCESS);

$this->server->set([
... other options here ...
'worker_num' => 2, // The number of worker processes to start
]);

Replies: 3 comments 3 replies

Comment options

I think you may be able to use this bash script:

https://gist.github.com/lotharthesavior/4c3aa47665d83a0d4fbdd293ac11f7cc

You must be logged in to vote
0 replies
Comment options

This may also be usable:

https://github.com/skoro/slim-swoole-integration

You must be logged in to vote
1 reply
@rbro
Comment options

@henrywood: thanks, I tried with the example server.php onhttps://github.com/skoro/slim-swoole-integration. I had to edit one line in HotCodeReloader.php to have it work:

old:
$this->timerId = $this->server->tick($this->msDelay, [$this, 'checkAndReload']);

new:
$this->timerId = \Swoole\timer::tick($this->msDelay, [$this, 'checkAndReload']);

After I did that and edited server.php, I got this error:

Warning: Swoole\Server::reload(): not supported with single process mode in /tmp/swoole/vendor/skoro/slim-swoole-integration/src/HotCodeReloader.php on line 32

Does server.php need to be structured differently for it to work?

Thanks.

Comment options

Maybe try something like:

$this->server = new Swoole\Http\Server("127.0.0.1", 9501, SWOOLE_BASE);

$this->server->set([
... other options here ...
'worker_num' => 2, // The number of worker processes to start
]);

If that does not work, try:

$this->server = new Swoole\Http\Server("127.0.0.1", 9501, SWOOLE_PROCESS);

$this->server->set([
... other options here ...
'worker_num' => 2, // The number of worker processes to start
]);

You must be logged in to vote
2 replies
@rbro
Comment options

Thanks, it seems to work with SWOOLE_PROCESS. With SWOOLE_BASE, I started getting these errors when I edited a file:

[2024-06-10 17:35:03 *22337.0] WARNING Worker_reactor_try_to_exit() (ERRNO 9101): worker exit timeout, forced termination

I may have more questions, but I will first try out some more complex examples with SWOOLE_PROCESS. Thanks again for your help.

@rbro
Comment options

I have one other question I was hoping to get help with:

I'm now looking at implementing a Coroutine HTTP Server. Onhttps://wiki.swoole.com/en/#/server/co_init, it says:

"some functionalities need to be manually implemented, such as handling reload functionality by listening to signals"

Do you have an example of how reloading can be done in a coroutine?

Would I pass $reuse_port=true to my original coroutinue, and then create another coroutinue when I want to reload, and then shutdown my original coroutine? Would that do it in a graceful way to not interrupt any connections?

Or is there a different way to structure it?

Thanks for your help.

Answer selected byrbro
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Category
Q&A
Labels
None yet
2 participants
@rbro@henrywood

[8]ページ先頭

©2009-2025 Movatter.jp