Table of Contents
使用 Composer 安装QPM(推荐)
1) 安装Composer
2) 在Composer配置文件中配置QPM
3) 安装QPM
4) 运行
直接下载QPM
1) 从github releases 下载最新稳定版本。
2) 解压到项目目录。
3) 注册自己编写的autoloader并运行。
Home Backend Development PHP Tutorial 安装和使用PHP进程管理框架 QPM

安装和使用PHP进程管理框架 QPM

Jun 23, 2016 pm 01:38 PM

QPM全名是 Quick Process Management Framework for PHP. PHP 是强大的web开发语言,以至于大家常常忘记PHP 可以用来开发健壮的命令行(CLI)程序以至于daemon程序。 而编写daemon程序免不了与各种进程管理打交道。QPM正式为简化进程管理而开发的类库。QPM的项目地址是: https://github.com/Comos/qpm

环境要求
  1. *nix系统。由于QPM的核心功能是基于pcntl扩展的,无法用于windows系统。
  2. PHP 5.4.x及以上版本,并且开启pcntl, posix。
安装并使用QPM

使用 Composer 安装QPM(推荐)

1) 安装Composer

Composer 是PHP用来管理软件包依赖关系的工具。使用Composer可以非常便利的实现依赖包的快速下载和安装。
使用以下命令,可以快速安装Composer:

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

也可参考:Composer安装指南。

2) 在Composer配置文件中配置QPM

使用Composer的项目,在项目目录下通常有composer.json文件。
可参考如下配置。

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

其中

"comos/qpm":"0.3.*"
Copy after login

表示依赖 comos/qpm 0.3.x版本。

3) 安装QPM

准备好composer.json, 执行 composer install 后,即可在 vendor/comos 找到qpm

4) 运行

运行前,脚本须先加载compser autoload.php文件。
例 test.php:

<?phprequire __DIR__.'/vendor/autoload.php';$pid = qpm\process\Process::current()->getPid();echo "PID: $pid\n";
Copy after login

执行 php test.php,终端输出 PID: 11210 (进程号)。

直接下载QPM

1) 从github releases 下载最新稳定版本。

例如 0.3.0版本。

2) 解压到项目目录。

tar zxvf 0.3.0.tar.gz
Copy after login

3) 注册自己编写的autoloader并运行。

由于qpm遵循psr-4,需要依赖autoloading机制加载类,如果项目没有注册适合的autoloader,用户需要自行实现autoloader。
例如 test1.php:

    <?php    spl_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";
Copy after login

执行 php test1.php,终端输出 PID: 11210 (进程号)。

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

Describe the SOLID principles and how they apply to PHP development. Describe the SOLID principles and how they apply to PHP development. Apr 03, 2025 am 12:04 AM

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

How to automatically set permissions of unixsocket after system restart? How to automatically set permissions of unixsocket after system restart? Mar 31, 2025 pm 11:54 PM

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

Explain the concept of late static binding in PHP. Explain the concept of late static binding in PHP. Mar 21, 2025 pm 01:33 PM

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

How to send a POST request containing JSON data using PHP's cURL library? How to send a POST request containing JSON data using PHP's cURL library? Apr 01, 2025 pm 03:12 PM

Sending JSON data using PHP's cURL library In PHP development, it is often necessary to interact with external APIs. One of the common ways is to use cURL library to send POST�...

Framework Security Features: Protecting against vulnerabilities. Framework Security Features: Protecting against vulnerabilities. Mar 28, 2025 pm 05:11 PM

Article discusses essential security features in frameworks to protect against vulnerabilities, including input validation, authentication, and regular updates.

Customizing/Extending Frameworks: How to add custom functionality. Customizing/Extending Frameworks: How to add custom functionality. Mar 28, 2025 pm 05:12 PM

The article discusses adding custom functionality to frameworks, focusing on understanding architecture, identifying extension points, and best practices for integration and debugging.

See all articles