Skip to content
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

Share tcp server port in multiple processes #52

Open
jimthunderbird opened this issue Mar 7, 2014 · 1 comment
Open

Share tcp server port in multiple processes #52

jimthunderbird opened this issue Mar 7, 2014 · 1 comment

Comments

@jimthunderbird
Copy link

Hi,
Is there a way php-uv can share tcp server port in multiple processes? Like what node.js's cluster module did?
"A single instance of Node runs in a single thread. To take advantage of multi-core systems the user will sometimes want to launch a cluster of Node processes to handle the load.

The cluster module allows you to easily create child processes that all share server ports."

Best Regards,
Jim

@rdlowrey
Copy link
Contributor

The most straight-forward way to do this is via the SO_REUSEPORT socket option. It's available in linux kernel versions >= 3.9. When assigned this allows multiple processes/threads to bind to the same address/port tuple without issue. It should be possible to add support for this where available.

Another option I've used (though not with php-uv) is to fork a process with the sockets already bound. The child forks can then accept clients on the same socket independently of one another though the distribution of clients may not be even across the children.

I haven't tried to build php-uv on windows but in Win you can bind multiple sockets on the same port by default and don't need any additional socket options so this behavior would already be available there.

With libuv this is something that's a lot easier to accomplish at the C layer right now :/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants