title: How to multi-thread with pThreads in PHP7? workers, pool, etc
body: <p>I am currently wanting to learn and implement <a href="https://github.com/krakjoe/pthreads" rel="nofollow">pthreads - github</a>. I have compiled <code>php7</code> with the necessary components and verified that <code>thread-safety</code> is enabled. My current example code has 4 child classes that belong to parent class <code>Canine</code>. How should I call the <code>Thread</code> class accordingly to execute <code>bark()</code> from all classes shown below at the same? Keeping in mind the ability to scale when classes grow from 4 to 100. Pools? Workers? </p>
  
  <pre><code> class Database {
      private $_host;
      private $_user;
      private $_pass;
      private $_dbname;
      private $_dsn;
      private $_options;
      public static $pdo;
      private $error;
  
      private $stmt;
  
      public function __construct() {
          $this-&gt;_host   = 'xxxxx';
          $this-&gt;_user   = 'xxxxx';
          $this-&gt;_pass   = 'xxxxx';
          $this-&gt;_dbname = 'xxxxx';
          $this-&gt;_dsn    = 'mysql:host=' . $this-&gt;_host . ';dbname=' . $this-&gt;_dbname;
          // Set options
          $this-&gt;_options = array(
              PDO::MYSQL_ATTR_LOCAL_INFILE =&gt; true,
              PDO::ATTR_PERSISTENT         =&gt; true,
              PDO::ATTR_ERRMODE            =&gt; PDO::ERRMODE_EXCEPTION,
              PDO::ATTR_TIMEOUT            =&gt; 1,
          );
      }
  
      public function __sleep() {
          return array('_dsn', '_user', '_pass');
      }
  
      public function __wakeup() {
          $this-&gt;connect();
      }
  
      public function connect() {
          try {
              return self::$pdo = new PDO($this-&gt;_dsn, $this-&gt;_user, $this-&gt;_pass, $this-&gt;_options);
          } catch (PDOException $e) {
              $this-&gt;error = $e-&gt;getMessage();
          }
      }
  }
  
  class DataAccessObject {
      protected $database;
  
      public function __construct() {
          //Create Instance of DB
          $this-&gt;database = (new Database())-&gt;connect();
      }
  
      public function insertQuery($query) {
          try {
              $select = $this-&gt;database-&gt;prepare($query);
              $select-&gt;execute();
              $results = $select-&gt;fetchAll(PDO::FETCH_ASSOC);
          } catch (Exception $e) {
              echo "Failed: " . $e-&gt;getMessage();
          }
          return true;
      }
  }
  
  class Helper extends DataAccessObject {
  //code elided
  }
  
  abstract class Canine extends Helper {
      abstract public function bark();
  }
  
  //Child Classes
  
  class GoldenRitriever extends Canine {
      public function bark() { echo 'arf-arf!&lt;br&gt;'; }
  }
  
  class Pitbull extends Canine {
      public function bark() { echo 'ruff-ruff!&lt;br&gt;'; }
  }
  
  class GermanShepherd extends Canine {
      public function bark() { echo 'wao-wao!&lt;br&gt;'; }
  }
  
  class LabradorRetriever extends Canine {
      public function bark() { echo 'woof-woof!&lt;br&gt;'; }
  }
  
  Creating instances and invoking `bark()`
  
  $golden_ritriever = new GoldenRitriever();
  $golden_ritriever-&gt;bark();
  
  $pitbull = new Pitbull();
  $pitbull-&gt;bark();
  
  $german_shepherd = new GermanShepherd();
  $german_shepherd-&gt;bark();
  
  $labrador_retriever = new LabradorRetriever();
  $labrador_retriever-&gt;bark();
  </code></pre>