For example, there is a remote API with the following calls:
getGroupCapacity(group)
setGroupCapacity(group, quantity)
getNumberOfItemsInGroup(group)
addItemToGroup(group, item)
deleteItemFromGroup(group, item)
The task is to add some element to any group. Groups have a capacity. Therefore, we must first check to see if the group is full. If so, increase capacity and then add item. Something like this (for example, the API is rendered using SOAP):
function add_item($group, $item) {
$soap = new SoapClient(...);
$capacity = $soap->getGroupCapacity($group);
$itemsInGroup = $soap->getNumberOfItemsInGroup($group);
if ($itemsInGroup == $capacity) {
$soap->setGroupCapacity($group, $capacity + 1);
}
$soap->addItemToGroup($group, $item);
}
Now, what if addItemToGroup failed (the item was bad)? We need to roll back the group.
Now imagine that you need to add 10 elements for grouping, and then configure the added elements with some properties - all in one transaction. This means that if it does not work somewhere in the middle, you must drop everything in its previous state.
IF ? , , , ( PHP)?
UPD: SOAP - . , TCP. , API .
UPD2: , . PHP.
!