1

I am coming from java background which has rich threading framework. In the past , I kept hearing that PHP does not support threading. But below code from this site creates the thread in PHP in almost same way as java does. So what's the difference ?

<?php

class ChildThread extends Thread {
    public $data;

    public function run() {
      /* Do some work */

      $this->data = 'result';
    }
}

$thread = new ChildThread();

Also I read below statements on google

Avoid the idea of running paralell tasks (threads or processes) in PHP. It has some modules for this purpose, but they are not available on every platform and are not part of the PHP core, so the chances for you to be able to use them are very low.

This way wil not will work in every single environment

So My question above way of creating thread thread does not work on every platform(which platform for example) ? Does it mean there is no true way of creating thread that works on all environment ?

Joe C
  • 15,324
  • 8
  • 38
  • 50
user3198603
  • 5,528
  • 13
  • 65
  • 125
  • If your question is about PHP, please do not tag it with Java. There is no benefit to you attracting Java experts to this question. – Joe C Nov 25 '18 at 16:09
  • 1
    [From the author of `pthreads`](https://stackoverflow.com/questions/209774/does-php-have-threading/14548828#14548828) – revo Nov 25 '18 at 16:44
  • Possible duplicate of [Multithreading in PHP 7](https://stackoverflow.com/questions/42266813/multithreading-in-php-7) – revo Nov 25 '18 at 16:49
  • PHP don't work with threads in a native way, it's necessary extensions to enable this kind of feature and only will work properly on CLI-based applications. For parallelism you can work with pcntl functions or pthread, but as i said, it maybe not practicable on web apps. – Gabriel Pereira Jan 25 '19 at 13:54

0 Answers0