GithubHelp home page GithubHelp logo

comos / qpm Goto Github PK

View Code? Open in Web Editor NEW
75.0 19.0 23.0 208 KB

QPM, the process management framework in PHP, the efficient toolkit for CLI development. QPM provides basic daemon functions and supervision mechanisms to simplify multi-process app dev.

License: GNU General Public License v3.0

PHP 100.00%

qpm's Introduction

QPM Build Status

QPM全名是 Quick(or Q's) Process Management Framework for PHP. PHP 是强大的web开发语言,以至于大家常常忘记PHP 可以用来开发健壮的命令行(CLI)程序以至于daemon程序。 而编写daemon程序免不了与各种进程管理打交道。QPM正是为简化进程管理而开发的类库。

QPM是一个专门针对*nix CLI编程的框架,不可用于Windows环境和CGI编程。

QPM 目前包括4个主要的子模块:

  • Process 基础进程管理,包括fork的面向对象封装;
  • Supervision 进程监控,实现了OneForOne、MultiGroupOneForOne 和 TaskFactoryMode 三种模式;
  • Pid 支持PID文件管理;
  • Log 实现了用于测试的简易文件日志,同时支持接入 Psr 标准的日志实现,例如 Monolog。

examples目录下有若干使用的示例,tests是测试用例所在的目录。

QPM也支持通过Composer安装:composer require comos/qpm

也可通过其他方式下载并部署QPM,参考安装和使用QPM

QPM 运行时,必须使用autoloader,强烈建议使用Composer自带的autoloader,否则需要自行注册autoload回调,可参考:autoload.php

通过Wiki 可以获取更多信息。

QPM 最新版本是v1.0,与 之前的v0.3有较大的变化,使用时请留意兼容性问题,如果没有修改代码的计划,请不要从v0.3升级到v1.0。


QPM’s full name is Quick Process Management Framework in PHP.

PHP is so powerful in web development, that people always forget that it could be used to write robust CLI programs, even daemon programs. Process management is a base of daemon programming. QPM is such a library to simplify process management. QPM is a CLI programming framework based on *nix systems. It cannot be used in Windows and CGI environment.

There're four main packages:

  • Process, the basic process management, includes an OO style encapsulation of pcntl_fork.
  • Supervision, the process supervisor, supports one-for-one mode, multi-group-one-for-one mode and task factory mode.
  • Pid manages the PID file to prevent the the daemon is started duplicately.
  • Log includes a file based simple Logger as the test purpose. The Logger supports PSR-3, so you can connect QPM to any implementer of PSR-3, such as Monolog.

We provide rich usage samples in ‘examples’ directory.

The library is covered by unit tests well, all the tests are in ‘tests’ directory.

You can install QPM by composer:


composer require comos/qpm

Notice: the lastest verison v1.0 is not compatible with v0.3. If you're using v0.3 or earlier versions, don't upgrade the library without refactoring and test.

The other ways to get and use QPM, see Getting Started.

qpm's People

Contributors

13leaf avatar bigbigant avatar bryant1410 avatar zephor5 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

qpm's Issues

getParent这个没有定义哈

Notice: Undefined variable: msq in /Users/chengtao/opencode/php/qpm/_examples/qpm_daemon.php on line 44

localhost:qpm chengtao$ find . -name "*.php" |xargs grep "getParent"
./_examples/qpm_daemon.php: $msg = sprintf("PID: %d\tPPID:%d\n", Process::current()->getPid(), Process::current()->getParent()->getPid());
localhost:qpm chengtao$ pwd
/Users/chengtao/opencode/php/qpm

添加到 https://packagist.org/

# composer install
Loading composer repositories with package information
Installing dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

Problem 1
- The requested package comos/qpm could not be found in any version, there may be a typo in the package name.

Potential causes:

Read http://getcomposer.org/doc/articles/troubleshooting.md for further common problems.

判断类实现了哪些借口好像不能用这个get_parent_class,应该用ReflectionClass吧?

/qpm/library/qpm/supervisor/Config.php line: 85行
if (isset($config['runnableClass'])) {
$clazz = $config['runnableClass'];
if (!is_subclass_of($clazz, '\qpm\process\Runnable')) {
throw new \InvalidArgumentException('runnableClass must be an implemention of \qpm\process\Runnable');
}
$this->_factoryMethod = function() use($clazz) {
return array((new $clazz()), 'run');
};
return;
}
is_subclass_of 这个函数好像不能获得这个类实现的接口列表

class Test extends \qpm\supervisor\Supervisor{}
class QWorker implements \qpm\process\Runnable{
public function run(){
while(true) {
echo "+++run2,pid:".posix_getpid()."\n";
require_once '../lib/RabbitMq.class.php';
RabbitMq::getQueue()->consume(function($envelope, $queue) {
$msg = $envelope->getBody();
echo $msg."\n"; //处理消息
$queue->ack($envelope->getDeliveryTag()); //手动发送ACK应答
});
}
return 0;
}
}
echo "Out:".get_parent_class('Test');echo "\n";
echo "Out:".get_parent_class('QWorker');echo "\n";
print_r ((new ReflectionClass("QWorker"))->getInterfaceNames());echo "\n";
exit;

------------------
localhost:collect chengtao$ /usr/local/php/bin/php main.php
Out:qpm\supervisor\Supervisor
Out:
Array
(
[0] => qpm\process\Runnable
)

localhost:collect chengtao$

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.