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
- *nix System. Because the core functionality of QPM is PCNTL-based, it cannot be used with Windows systems.
- 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