Getting Started - Comos/qpm GitHub Wiki

Environment requirements

  1. *nix systems. The core of QPM is Pcntl extension, it cannot be used in Windows.
  2. PHP 5.3 or later versions, ext-pcntl, ext-posix。

Installing and Using

Install QPM by Composer (Recommended)

1) Install Composer

Composer is a dependency management tool in PHP. You can download and install the depended packages automately by Composer. First, you have to execute following commands to install Composer self:

curl -sS https://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer

Reference:Composer guide

2) Make composer.json

A project to use Composer, you need a composer.json first. Put the file to the root directory of the project. The content looks like following.

    { 
      "require": {
        "monolog/monolog": "1.0.*",
        "comos/qpm":"0.3.*"
      }
    }

The part

"comos/qpm”:”~1.0"

means that the comos/qpm v1.0.x is required.

3) Install the dependencies, include QPM

As you have prepared composer.json, run composer install. You'll find qpm in vendor/comos.

4) run

Before using those packages,the script must include the autoload.php generated by Composer.

<?php
require __DIR__.'/vendor/autoload.php';
$pid = Comos\Qpm\Process\Process::current()->getPid();
echo "PID: $pid\n";

Execute php test.php,it outputs 'PID: {process ID}’.

Download QPM manually

1) Get the latest stable release from github.

For example v1.0.0

2) Unarchive to the directory.

tar zxvf v1.0.0.tar.gz

3) Register an autoloader and run.

Because QPM follows PSR-4,an autoloader is required. You may make one by yourself. E.g. test1.php:

    <?php
    spl_autoload_register(function ($class) {
        $prefix = ‘\\Comos\\Qpm';
        $baseDir = __DIR__ . ‘/path-to-qpm/src';
        $len = strlen($prefix);
        if (strncmp($prefix, $class, $len) !== 0) {
            return;
        }
        $relativeClass = substr($class, $len);
        $file = $baseDir . str_replace('\\', '/', $relativeClass) . '.php';
        if (file_exists($file)) {
            require $file;
        }
    });
    
    $pid = Comos\Qpm\Process\Process::current()->getPid();
    echo "PID: $pid\n";

Execute php test1.php,it outputs 'PID: {process ID}’.