-1

I know that PHP supports now Threads and i read here Python multi-threading is not better than muli-threading in java since Python has some issues with GIL.

So i sepposed that Python multi-threading will also not be better than muli-threading in php. As PHP use the same style like in java to create threads, in addition php uses pthread to implements threads, which is wide popular library.

What do you suggest ?

Community
  • 1
  • 1
Ben Ishak
  • 669
  • 3
  • 11
  • 27

1 Answers1

-3

Python does indeed have a Global Interpreter Lock. This means you can't use threads to spread one program over multiple cores on the same machine. But running the same program on multiple cores is not what threads was designed for anyway, and doing so is not easy. However, you can use the multiprocessing module to spread a program over multiple cores, so this is no big deal.

I don't know if PHP has a GIL or not, but as you see above it's really not important.

Even if PHP's threading was slightly better than Pythons, that's a bad reason to choose PHP. In fact pretty much any reason except "I don't have a choice" is a bad reason. Ref1 Ref2

Lennart Regebro
  • 167,292
  • 41
  • 224
  • 251
  • It's not strictly true that "you can't use threads" to utilize multiple cores. The GIL means that no two cores can be executing in the main CPython's interpreter code concurrently. However, you'll still see some benefits for some workloads even with the GIL with threading. However, as you say, the multiprocessing module (in the standard libraries since 2.6) is the better way to go. Note that some C/binary extensions to CPython (such as Numpy) are written to release the GIL and have their own multi-threading support. So some computational workloads can benefit from multiple cores as well. – Jim Dennis Oct 25 '15 at 20:44