安装和使用PHP进程管理框架 QPM
QPM全名是 Quick Process Management Framework for PHP. PHP 是强大的web开发语言,以至于大家常常忘记PHP 可以用来开发健壮的命令行(CLI)程序以至于daemon程序。 而编写daemon程序免不了与各种进程管理打交道。QPM正式为简化进程管理而开发的类库。QPM的项目地址是: https://github.com/Comos/qpm
环境要求- *nix系统。由于QPM的核心功能是基于pcntl扩展的,无法用于windows系统。
- PHP 5.4.x及以上版本,并且开启pcntl, posix。
使用 Composer 安装QPM(推荐)
1) 安装Composer
Composer 是PHP用来管理软件包依赖关系的工具。使用Composer可以非常便利的实现依赖包的快速下载和安装。
使用以下命令,可以快速安装Composer:
curl -sS https://getcomposer.org/installer | phpmv composer.phar /usr/local/bin/composer
也可参考:Composer安装指南。
2) 在Composer配置文件中配置QPM
使用Composer的项目,在项目目录下通常有composer.json文件。
可参考如下配置。
{ "require": { "monolog/monolog": "1.0.*", "comos/qpm":"0.3.*" } }
其中
"comos/qpm":"0.3.*"
表示依赖 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";
执行 php test.php,终端输出 PID: 11210 (进程号)。
直接下载QPM
1) 从github releases 下载最新稳定版本。
例如 0.3.0版本。
2) 解压到项目目录。
tar zxvf 0.3.0.tar.gz
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";
执行 php test1.php,终端输出 PID: 11210 (进程号)。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Alipay PHP...

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,

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 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...

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

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�...

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

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