Download the PHP package gabrielelana/violent-death without Composer
On this page you can find all versions of the php package gabrielelana/violent-death. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download gabrielelana/violent-death
More information about gabrielelana/violent-death
Files in gabrielelana/violent-death
Package violent-death
Short Description Native extension that generates segmentation faults
License MIT
Informations about the package violent-death
Violent Death 
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
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 effectint $msToAgonizeAtMost
: At most how many milliseconds to wait before the poison will end your code. Default0
int $probabilityToDie
: The percentage of probability to die. An integer between1
and100
. Default100
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 between1
and100
. Default16
In Blast Extension: die_violently_after($msToWait)
In Blast Extension: die_violently($msToWait)
Install
You can comfortably install the package through composer
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
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
Self-Promotion
If you like this project, then consider to:
All versions of violent-death with dependencies
ext-blast Version *