3

Possible Duplicate:
Does PHP have threading?

I found this: http://php.net/manual/en/function.pcntl-fork.php

But I can't tell if those are threads or processes, I'm confused. They use both words.

In case you have an alternate solution, this is what I need threads for: I want to create a real-time game using web sockets, and I thought of having a single process running in the background, that spawns one thread for each game (or room) on demand.

Community
  • 1
  • 1
HappyDeveloper
  • 12,480
  • 22
  • 82
  • 117

3 Answers3

3

pcntl_fork creates a new process. While the word "thread" is used in the documentation, "process" is much more prominent:

The pcntl_fork() function creates a child process that differs from the parent process only in its PID and PPID.

PHP does not support multithreading (and it cannot assume that the web server itself is multithreaded in general).

Finally, spawning a thread for each anything is a naive approach to scaling that does not scale beyond a certain not-so-late point. I suggest looking into alternate architectures.

Jon
  • 428,835
  • 81
  • 738
  • 806
2

That's just a wrapper for the C fork() function. It creates processes, not threads. PHP does not support multithreading.

Emil Vikström
  • 90,431
  • 16
  • 141
  • 175
0

* PHP does not support multithreading.