Installing and using the PHP process management Framework QPM

Source: Internet
Author: User
Tags autoload autoloader composer install

QPM full name is the Quick Process Management Framework for PHP. PHP is a powerful web development language, so many people often forget that PHP can be used to develop robust command-line (CLI) programs to daemon programs. and the preparation of daemon program is unavoidable to deal with various process management. QPM is a class library that is formally developed for simplified process management. QPM's project address is: HTTPS://GITHUB.COM/COMOS/QPM

Environmental requirements
    1. *nix System. Because the core functionality of QPM is PCNTL-based, it cannot be used with Windows systems.
    2. PHP 5.4.x and later, and open Pcntl, POSIX.
Install and use QPM with Composer installation QPM (recommended) 1) Install Composer

Composer is a tool that PHP uses to manage software package dependencies. The fast download and installation of dependent packages can be easily implemented using composer.
You can quickly install composer by using the following command:

-sS https://getcomposer.org/installer | phpmv composer.phar /usr/local/bin/composer

Also refer to: Composer Installation Guide.

2) Configure the QPM in the composer configuration file

With composer projects, there are usually Composer.json files under the project directory.
Refer to the configuration below.

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

which

"comos/qpm":"0.3.*"

Represents a dependent COMOS/QPM 0.3.x version.

3) Install QPM

When you are ready to Composer.json, perform composer install, you can find QPM in Vendor/comos

4) Run

Before running, the script must load the Compser autoload.php file first.
Example test.php:

<?phprequire__DIR__.‘/vendor/autoload.php‘;$pid = qpm\process\Process::current()->getPid();echo"PID: $pid\n";

Execute PHP test.php, terminal output pid:11210 (process number).

Download the latest stable version of QPM1 directly from GitHub releases.

For example, version 0.3.0.

2) Unzip to the project directory.
tar zxvf 0.3.0.tar.gz
3) Register your own autoloader and run the program.

Since QPM follows Psr-4, it relies on the autoloading mechanism to load the class, and if the project does not register the appropriate autoloader, the user needs to implement autoloader itself.
For example test1.php:

    <?phpSpl_autoload_register ( function ($class) {        $prefix=' qpm\\ ';$baseDir=__dir__.'/qpm-0.3.0/library ';$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= Qpm\process\process::current ()->getpid ();Echo "PID: $pid \ n";

Execute PHP test1.php, terminal output pid:11210 (process number).

Installing and using the PHP process management Framework QPM

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.