tpunt / pht

A new threading extension for PHP
BSD 3-Clause "New" or "Revised" License
179 stars 14 forks source link

Future Development #9

Closed wagnert closed 4 years ago

wagnert commented 4 years ago

Hi Thomas,

I'm one of the core developers of appserver.io a PHP application server. As we have been one of the first that uses pthreads, you have maybe heard of that project. We still stuck a little bit on PHP 5.6 as Joe has breaking changes from pthreads 2 to 3 and we didn't find the time to update yet. As Joe Watkins mentioned, that pthreads will not be supported anymore, we're looking for a replacement of pthreads to update appserver.io to PHP 7+ and found pht which seems very promising. I've some questions and we'll be happy to hear your thoughts about that

  1. Is further development of pht save? I'm asking because it'll be for sure a whole lot of work to refactor appserver.io to use pht instead of pthreads
  2. As I didn't find any example about how to use resources like sockets, I want to know if it is possible and safe to share sockets between threads? As appserver.io provides webserver functionality this is one of the most important topics that we've to figure out and test if it'll be possible at all with pht.
  3. Can you give us a rough estimation about the performance we can expect from pht in comparison to pthreads. We slightly customized pthreads and got a really good performance which allows us to use it in production for some high traffic projects.
  4. As we see that you also maintained pthreads i want to ask you, if you've something like a migration path from pthreads to pht?

In one of the previous issues I see that you actually don't have the time to work on pht, but hopefully that'll change in the future :)

Best Regards

tpunt commented 4 years ago

Hey Tim,

Regarding your questions:

  1. Broadly, yes, this is a project I will be coming back to. However, I would not like to recommend to you (or anyone else) to start using this extension in production until I have started development on it again. Since Parallel is currently being actively developed and maintained, it would be a better idea to look into that extension instead for your multithreading needs.

  2. Multithreaded sockets are not possible with this extension. This may be introduced in future, however that is some way off.

  3. I don't think there are any performance benchmarks on this.

  4. No migration path exists between the two extensions, because they are very different in how they approach things. Going from one to the other will require a complete rewrite, and so trying to outline a migration path isn't going to be particularly useful.

I do hope to get back to this project in the not-too-distant future :) Thanks!

feamsr00 commented 4 years ago

For whats its worth, re point 4, Parallel is also wildly different from pthreads. As of this writing Mr. Watkins has not released a migration guide per se (and may not). So it's still 6 in one hand, half dozen in the other.

wagnert commented 4 years ago

Hi Thomas,

thanks for your quick answer. As we need socket support, I think it'll actually don't make sense to migrate. We'll have a look at pht in the future again to see how the development will go on.

We hope that you'll find the time to improve pht as it seems to be a very interesting project :)

Best Regards

zhaoyanliang2 commented 4 years ago

@wagnert Hello, wagnert! I am interested in your project, you can check my code, maybe it helps you. https://gist.github.com/zhaoyanliang2/ded89c60251c6320278c9313dbd93f52 I actually use it on Windows, in theory it should be able to use it on Linux as well. It provides two php functions, stream_fd_fetch stream_fd_attach.

wagnert commented 4 years ago

Hi @zhaoyanliang2 thanks for asking. As I'm not really into C development, so I'm not the right one to decide if it can help or not. If you'll provide a PHP extension that provides multithreaded socket support, I'll install and test it for sure :)