Answer the question
In order to leave comments, you need to log in
How to catch an error in the root script and not fall into Error?
There is a script that runs in cron. It fetches data from the base (list), iterates through the list with foreach and performs an operation on each element of the list. When performing an operation on one of the elements, an error may occur - accordingly, the script crashes and does not complete to the end. Pseudocode:
$all = getData();
foreach ($all as $one){
$one->doSomething(); //вот тут оно может упасть и не продолжить скрипт.
}
Answer the question
In order to leave comments, you need to log in
So far, he himself came up with a stupid way to fork the process:
foreach ($all as $one) {
$pid = pcntl_fork();
if ($pid == -1) {
die('could not fork');
} else if ($pid) {
pcntl_wait($status); //Protect against Zombie children
continue;
} else {
$one->doSomething();
exit(0);
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question