定制 gabrielelana/violent-death 二次开发

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

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

gabrielelana/violent-death

Composer 安装命令:

composer require gabrielelana/violent-death

包简介

Native extension that generates segmentation faults

README 文档

README

How do you know that your code is fault tolerant? How can you verify that it will not break in some terrible and irrecoverable way when something bad happens? This package will help you to simulate the most lethal events that your code can possibly face in its life.

Scenario

You want to test the fault tolerance of your code. You want to make sure that your code will always leave this world with things in a consistent state. The problem is that the kind of failure you can create inside PHP are

  • Soft: they are more or less managed by the PHP interpreter
  • Predictable: they are created by you in a synchronous way, in real life sh*t happens when you don't expect it, but you cannot simulate a failure say when you are executing a query or when you are making a request to a remote server

If you are asking yourself how can you manage this kind of failures then graceful-death it's your answer

Usage

<?php

require __DIR__ . "/../vendor/autoload.php";

// The output will be something like:
//
// What is this? Should I drink it?
// There, I drank it, I will die eventually...
// Still there :-)
// Still there :-)
// …
// Still there :-)
// [1]    26584 segmentation fault (core dumped)  php examples/drink_poison.php

echo "What is this? Should I drink it?\n";
drink_poison($msToTakeEffect=500, $msToAgonizeAtMost=1000);
// Here we have created a background thread that will wait
// at least for 500ms and at most 1500ms before to cause
// an horrible death with a segmentation fault

echo "There, I drank it, I will die eventually...\n";
while(true) {
    echo "Still there :-)\n";
    usleep(50000);
}

How Does It Work?

To create a segmentation fault we rely on a C extension. To eventually create a segmentation fault in the future (while the code is doing something else) we create a background thread that will wait some amount of time and then cause a segmentation fault.

Gotchas

You need to be able to compile a PHP extension and you need the pthread library installed. The segmentation fault it's not guaranteed on all platforms (aka for every combination of C compiler, OS kernel and CPU architecture), so it may not work, AFAIK the notion of segmentation fault it's not part of any ANSI C standard so there's no standard way to create a genuine segmentation fault.

Overview

drink_poison($msToTakeEffect, $msToAgonizeAtMost, $probabilityToDie)

It will create a segmentation fault at least after $msToTakeEffect milliseconds and at most after $msToTakeEffect + $msToAgonizeAtMost milliseconds. This will happen asynchronously in a background thread so that after this call the code can continue its normal flow

  • int $msToTakeEffect: How many milliseconds to wait before the poison takes effect
  • int $msToAgonizeAtMost: At most how many milliseconds to wait before the poison will end your code. Default 0
  • int $probabilityToDie: The percentage of probability to die. An integer between 1 and 100. Default 100

play_russian_roulette($probabilityToDie)

It will probably create a segmentation fault. The percentage of probability can be passed as parameter

  • int $probabilityToDie: The percentage of probability to die. An integer between 1 and 100. Default 16

In Blast Extension: die_violently_after($msToWait)

In Blast Extension: die_violently($msToWait)

Install

You can comfortably install the package through composer

$ composer require "gabrielelana/violent-death"

But before you need to install the blast native extension

Install Native Extension

To make sure to cause the most possible damage we need the most powerful and reliable weapon of self-destruction known to man: the C language

$ phphize
$ ./configure --with-pthread
$ make
$ sudo make install

Hopefully now the extension is compiled and installed. Now you need to enable it appending extension=blast.so in your php.ini file. Run the following commands, if you see the green bar then you are good to go

$ composer install
$ vendor/bin/phpunit

Self-Promotion

If you like this project, then consider to:

gabrielelana/violent-death 适用场景与选型建议

gabrielelana/violent-death 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4 次下载、GitHub Stars 达 28, 最近一次更新时间为 2014 年 05 月 21 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 gabrielelana/violent-death 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-05-21