adrian0350/php-daemon 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

adrian0350/php-daemon

Composer 安装命令:

composer require adrian0350/php-daemon

包简介

Bring workers to your web projects using PHP!

README 文档

README

With PHPDaemon you'll be able to run simple one-time daemons in any case you find yourself in a situation where you need to run an external script, meaning you need a Helper in your web project or what not.

This class works by storing a pid inside your script's dir as .script_file.pid (files starting wiht . are hidden by default).

Script output (logging) will be set in $options with the keys (boolean) log and (string) log_path.

If log is set to true and no log_path is provided or is invalid it will log in the script's directory.

If log is set to true and log_path is provided and valid it will log into the given log_path.

Log's name will be your script_file name ending with .log.

Example: For the pid /your/daemon/path/to/script_file.php would be /your/daemon/path/to/.script_file.php.pid and for the log /your/daemon/path/to/script_file.php without a log_path, it would be /your/daemon/path/to/script_file.php.log.

PHP Version

This class is compatible with PHP 5.4 and above due to the use of namespaces and PHP_BINARY constant.

Installing

Add this library to your composer configuration. In composer.json:

  "require": {
    "adrian0350/php-daemon": "1.*"
  }

OR

If you're using bash.

$ composer require adrian0350/php-daemon

Usage

For usage just call the methods from your PHPDaemon instance object.

<?php

// Start by including the class (if 1 level down).
include_once dirname(__FILE__).'/lib/PHPDaemon.php';

Usage — instantiating

Prepare three arguments you'll need.

  • Script's compatible binary file path [OPTIONAL].
  • Daemon script file path.
/**
 * Binary file path (per se) [OPTIONAL].
 *  · php
 *  · bash
 *
 * You could run '$ which php' in console
 * and get binary's filepath or use PHP's (^5.4) constant PHP_BINARY (although it's already being used internally).
 *
 * @var string $binary Binary filepath.
 */
$binary = '/opt/local/bin/php';

/**
 * The daemonized † filepath & filename.
 *
 * @var string $script Filepath & filename.
 */
$script = dirname(__FILE__).'/daemon/test.php';

/**
 * Logging options.
 *
 * @var array $options Includes log & log_path.
 */
$options = array(
	'log' => true,
	'log_path' => '/your/log/path'
);

// Instance receives 3 arguments (binary as optional).
$PHPDaemon = new PHPDaemon\PHPDaemon($script, $options, $binary);

Usage — instance handling

if ($PHPDaemon->isAlive())
{
	echo mb_convert_encoding('&#x1F608;', 'UTF-8', 'HTML-ENTITIES');
	echo ' Your daemon is alive and running!'.PHP_EOL;
}
else
{
	if ($PHPDaemon->start())
	{
		echo 'You\'ve unleashed the beast!'.PHP_EOL;
	}
	else
	{
		echo $PHPDaemon->error['message'].PHP_EOL;
	}
}

Usage — stoping daemonized scripts

if ($PHPDaemon->stop())
{
	echo mb_convert_encoding('&#x1F608;', 'UTF-8', 'HTML-ENTITIES');
	echo ' Your daemon has been stopped from deminishing the world!'.PHP_EOL;
}
else
{
	// Print out error message.
	echo $PHPDaemon->error['message'];
}

adrian0350/php-daemon 适用场景与选型建议

adrian0350/php-daemon 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 46 次下载、GitHub Stars 达 1, 最近一次更新时间为 2017 年 09 月 23 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「php」 「daemon」 「script」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 adrian0350/php-daemon 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 adrian0350/php-daemon 我们能提供哪些服务?
定制开发 / 二次开发

基于 adrian0350/php-daemon 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-09-23