3

How to do multithreading in PHP7? The first problem I see with pthread is coming directly from PHP manual.

https://secure.php.net/manual/en/intro.pthreads.php

The pthreads extension cannot be used in a web server environment. Threading in PHP should therefore remain to CLI-based applications only.

Is is safe to oversee this warning, and spawn some threads on HTTP requests?

Amr Eladawy
  • 4,193
  • 7
  • 34
  • 52
  • 1
    did you tried doing that .. Or use some other things like Rabbit MQ, Gearman etc. – M A SIDDIQUI Feb 16 '17 at 06:49
  • I read some about Gearman. My understanding is that it will be a standalone process to interface with. Did not check any MQs yet. But I am talking about the language itself. – Amr Eladawy Feb 16 '17 at 06:54
  • Gearman is good i use it .. you can use supervisord to monitor all your process. It basically works in back with as many threads you create – M A SIDDIQUI Feb 16 '17 at 06:57

1 Answers1

3

Is is safe to oversee this warning, and spawn some threads on HTTP requests?

The extension itself prohibits loading anywhere but CLI: Attempting to load in any other SAPI will result in a fatal error.

Joe Watkins
  • 17,032
  • 5
  • 41
  • 62
  • The library prohibits that. Yet there are workarounds http://www.smddzcy.com/2016/01/tutorial-multi-threading-in-php7-pthreads/ – Amr Eladawy Feb 16 '17 at 07:44
  • That's not a workaround, it's instructions for how to load pthreads in CLI only. – Joe Watkins Feb 19 '17 at 19:13
  • So what is the answer for the main question? How to do multithreading php7? – Amr Eladawy Feb 21 '17 at 05:57
  • 2
    @AmrElAdawy I think php doesn't support multi-threading when it comes to HTTP request. this conclude that you need another programming language. From my opinion the best language for this is GO. – Gujarat Santana Apr 06 '17 at 07:13