tigron / skeleton-transaction
Background tasks for skeleton
Requires
- php: >=8.2
- tigron/skeleton-core: >=5
- tigron/skeleton-database: >=0.3
- tigron/skeleton-lock: >=1.0
- tigron/skeleton-object: >=1.1
Requires (Dev)
- tigron/skeleton-database: dev-master
- tigron/skeleton-object: dev-master
Suggests
None
Provides
None
Conflicts
None
Replaces
None
- dev-master
- v6.0.3
- v6.0.2
- v6.0.1
- v6.0.0
- 5.x-dev
- v5.1.2
- v5.1.1
- v5.1.0
- v5.0.2
- v5.0.1
- v5.0.0
- 4.x-dev
- v4.0.1
- v4.0.0
- 1.x-dev
- v1.1.7
- v1.1.6
- v1.1.5
- v1.1.4
- v1.1.3
- v1.1.2
- v1.1.1
- v1.1.0
- v1.0.5
- v1.0.4
- v1.0.3
- v1.0.2
- v1.0.1
- v1.0.0
- v0.5.2
- v0.5.1
- v0.5.0
- v0.4.4
- v0.4.3
- v0.4.2
- v0.4.1
- v0.4.0
- v0.3.13
- v0.3.12
- v0.3.11
- v0.3.10
- v0.3.9
- v0.3.8
- v0.3.7
- v0.3.6
- v0.3.5
- v0.3.4
- v0.3.3
- v0.3.2
- v0.3.1
- v0.3.0
- v0.2.8
- v0.2.7
- v0.2.6
- v0.2.5
- v0.2.4
- v0.2.3
- v0.2.2
- v0.2.1
- v0.2.0
- v0.1.2
- v0.1.1
- v0.1.0
- v0.0.1
- dev-feature/pools
- dev-feature/quality
This package is auto-updated.
Last update: 2026-11-30 15:18:21 UTC
README
Description
Transactions for Skeleton. Transactions are used to perform background tasks.
Installation
Installation via composer:
composer require tigron/skeleton-transaction
Howto setup
Run the initial migrations
Create transactions
Transactions should all extend from \Skeleton\Transaction\Transaction and should implement the run() method:
<?php
/**
* Transaction_Test
*
* @author Christophe Gosiau <christophe@tigron.be>
*/
class Transaction_Test extends \Skeleton\Transaction\Transaction {
/**
* Run
*
* @access public
*/
public function run() {
// Do your thing
$data = $this->get_data();
}
}
Schedule your transaction
$transaction = new Transaction_Email_Order_Canceled();
$data = [ 'some_data' => 'some_value ];
$transaction->data = $data;
$transaction->schedule();
Manage the daemon
Start the transaction daemon with the skeleton binary:
skeleton transaction:daemon start
Stop the transaction daemon
skeleton transaction:daemon stop
Get the status of the daemon
skeleton transaction:daemon status
Interact with transactions
Get a list of all scheduled transactions
skeleton transaction:list
Run a transaction
skeleton transaction:run <transaction_id>
Show the log of a transaction
skeleton transaction:log <transaction_id_or_classname>
Logging every execution
Set a log file and every run of every transaction is written to it while it happens:
\Skeleton\Transaction\Config::$log_file = '/var/www/myproject/tmp/log/transaction.log';
Every line has the same shape, timestamp, event, child pid, detail:
2026-11-30 15:12:47.104 FORK pid 8104 Order_Invoice tx 4211 pool=none weight=10
2026-11-30 15:12:47.108 BEGIN pid 8104 Order_Invoice tx 4211 pool=none weight=10
2026-11-30 15:12:47.112 OUT pid 8104 invoice 991 generated
2026-11-30 15:12:47.412 DONE pid 8104 completed after 0.304s, peak 20MB of 512M
2026-11-30 15:12:47.420 REAP pid 8104 exited normally after 0.316s
| Event | Written by | Meaning |
|---|---|---|
FORK |
daemon | a child was spawned for this transaction |
BEGIN |
child | the child reached the runner |
OUT |
child | one line of output of the transaction |
DONE |
child | the run ended and its result was recorded, completed or failed |
ABORT |
child | the child ended without recording a result, with the last fatal error and peak memory |
REAP |
daemon | the child was reaped, with the decoded wait status |
LOCK |
daemon | the child is gone and the transaction is still locked |
DAEMON |
daemon | a lifecycle message about the daemon itself |
WARN |
daemon | something is wrong that belongs to no single child |
The child pid groups one execution: a transaction states its identity once, at
FORK and BEGIN, so ten children can write at the same time without their
lines becoming separable only after the fact.
REAP is the line to look for. It is written by the daemon rather than the
child, so it is the only one that survives a SIGKILL, and it names the signal
or the exit status. That is what separates the OOM killer, systemd clearing the
cgroup, a crash in an extension and a plain PHP fatal error. A child that dies
before recording its result leaves its transaction locked until the next daemon
start, when Transaction::unlock_all() releases it.
What a run echoes goes to the log file as OUT and to transaction_log.output,
and a failure is summarised on the DONE line with its full trace kept in
transaction_log.exception. The trace is only written to the log file when that
row itself could not be saved, which is the one case where there is nowhere else
left for it.
Reading the log is four greps:
# how did the children die
grep ' REAP ' transaction.log | grep -v 'exited normally'
# one execution, start to finish
grep -F ' pid 8104 ' transaction.log
# children the daemon made but never reaped: the daemon died mid-flight
grep -F ' FORK ' transaction.log | awk '{print $5}' | sort > forked
grep -F ' REAP ' transaction.log | awk '{print $5}' | sort > reaped
comm -23 forked reaped
Transaction concurrency
By default, a transaction will be running with pool set to null. All
transactions with pool null will run concurrently and as soon as a slot
becomes available.
Sometimes, however, transactions should not be run at the same time as another
transaction, for example because it is using a resource of which there is only
one. This can be fixed by assigning both of these transactions to run in the
same pool. Transactions with a non-null pool will run sequentially within
their pool.
To assign your transaction to a pool, override the get_pool() method:
public function get_pool(): string {
return 'mypool';
}
Transaction priority
Some transactions are more important than others. You can (de-)prioritise a transaction by modifying its weight. A lower weight will make the transaction float higher up in the queue with a higher priority, a higher weight will push it down and de-prioritise. The default weight is set to 10.
public function get_weight(): int {
return 42;
}
Monitor the daemon with Nagios
Skeleton Transaction Daemon can be monitored via its status file. The status file is updated every 5 seconds and can be configured via Config:
\Skeleton\Transaction\Config::$monitor_file = '/tmp/skeleton-transaction.status';
To monitor the daemon via Nagios, a \Skeleton\Core\Web\Module is provided which will read the status file and return an appropiate response.
To enable Nagios monitoring, make sure to create a module in your application that will handle the monitoring request:
<?php
/**
* Module monitor
*
* @author Christophe Gosiau <christophe@tigron.be>
*/
class Web_Module_Monitor extends \Skeleton\Transaction\Web\Module\Monitor {
}
Optionally, an authentication header can be configured:
\Skeleton\Transaction\Config::$monitor_authentication = 'YOUR_SECRET_STRING';
Nagios configuration
In Nagios, you should configure a command to call the service. We will use the
built-in check_http command as a starting point:
define command {
command_name check_skeleton_http
command_line /usr/lib/nagios/plugins/check_http -H $ARG1$ -u $ARG2$ -k 'X-Authentication: $ARG3$'
}
Your service definition could then look like this:
define service {
use generic-service
host_name hostname.example.com
service_description SKELETON
check_command check_skeleton_http!app.hostname.example.com!/monitor!AuThEnTiCaTiOnStRiNg
}