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('😈', '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('😈', '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 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 adrian0350/php-daemon 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Laravel Extension for handling CSV files
Swoole server process management
base daemon
A replica of the AWS Elastic Beanstalk worker SQS daemon (sqsd) in PHP
Composer plugin for running post-install/post-update scripts of your project's dependencies
Composer script for handling the creation of symlinks for any project. Optional to provide the path or define it on the composer install if it isn't already set.
统计信息
- 总下载量: 46
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 9
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-09-23