I'm planning to implement checkpointing to react to AWS Spot interruptions (which send a `SIGTERM`) in a Symfony application. I already implemented a listener for `console.signal` to log occurrences of such events, and `SignalableCommandInterface` on a specific Symfony command to log progress at interruption time for that command, and I was wondering if there was a library I should know about or a blog post I should read before implementing the checkpoint logic itself. What do you recommend? 🙂

To clarify, I need to implement this in a very long cronjob, and by "checkpointing" I mean saving progress, and starting over from where I left off during the next invocation of the command.

TIL :php: has an xkcd comic inside its manual: php.net/manual/en/control-stru

I'm looking at this page because a silly part of my brain is wondering if "starting over" might be a legitimate use case for `goto` 😅

Consider the following piece of code

```
public function __invoke()
{
a();
b();
c();
d();
e();
f();
g();
}
```

You know the cronjob has been interrupted while in `c()`. How would you go about starting over from `c()` ?

Suivre

@greg0ire I have already done the following code in the past:

```
switch($step) {
case 1:
a();
case 2:
b();
case 3:
c();
}
```

it's not sexy but it's efficient ;)

In PHP, another way to do is to use dynamic function name.

functions are named step_1, step_2, step_3,... and you can execute it using by assigning $step = "step_3"; then invoke it $step(); (then you increment a value to 4.)

@Vimar Oh yeah, I should definitely go with that rather than `goto`. 👍

@greg0ire using the second way, your invoke method should be :

```
public function __invoke($step = 1) {
while(!$isFinished) {
$currentStep = 'step_' . $step;
if (function_exists($$currentStep)) {
$currentStep();
$step++;
} else {
$isFinished = true;
}
}
}
```

that way if I want to declare a new step later I only need to declare a new function/method with the correct name.

Inscrivez-vous pour prendre part à la conversation
techlover

Technology lovers, here we are — (development, digital artwork, science…)