定制 consatan/pdaemon 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

consatan/pdaemon

Composer 安装命令:

composer require consatan/pdaemon

包简介

Running PHP script in daemon mode at CLI.

关键字:

README 文档

README

PDaemon

Running PHP script in daemon mode at CLI. Not available on Windows platforms.

Install

Requirements
  • PHP >= 5.4
  • pcntl extension
  • posix extension
  • sysvsem extension
Use composer (recommend)
composer require consatan/pdaemon
Download from github
git clone https://consatan.github.com/pdaemon.git

How to use

Simple daemon

<?php

require './vendor/autoload.php';

class DemoDaemon extends \Consatan\PDaemon\PDaemon
{
    protected function exec()
    {
        // Your code here.
        echo 'Running in children, PID: ' . posix_getpid() . PHP_EOL;
        // You can access your custom variable in $this->options
        // echo $this->options['your_variable'] . PHP_EOL;
        sleep(3);
    }
}

// Fork 3 children processes, pid file in /var/run/pdaemon.pid
$daemon = new DemoDaemon(['pool' => 3, 'your_variable' => 'hello world']);
$daemon->run();

You can stop daemon process list this

<?php

require './vendor/autoload.php';

// replace to your pid path
$pid = file_get_contents('/var/run/pdaemon.pid');

if (false === $pid) {
    // pid file cannot read or not exists.
    exit(-1);
}

$pid = (int)$pid;

if (0 >= $pid) {
    // invalid pid
    exit(-1);
}

// This is a safe terminat function, it will stop process when all children processes stop
posix_kill($pid, SIGTERM);

// You can forced stop the daemon like this: (non-recommended);
// posix_kill($pid, SIGKILL);

Todo

  • Unit test
  • Handling reload signal
  • Handling status signal

统计信息

  • 总下载量: 23
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 6
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 6
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: BSD
  • 更新时间: 2017-02-14

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固