Join 4,000+ others and never miss out on new tips, tutorials, and more.
Latest version:
pecl install openswoole-25.2.0 | composer require openswoole/core:22.1.5
<?php OpenSwoole\Coroutine::cancel(int $cid): bool
Coroutine ID, the coroutine ID you want to cancel/terminate. You cannot cancel the current coroutine.
Returns true
if the coroutine was successfully cancelled and false
if there was a problem, use OpenSwoole\Util::getLastErrorCode()
to see what went wrong.
Cancel the execution (terminate) of a coroutine based on a coroutine ID. You can get the ID of a coroutine with Coroutine::getCid()
, this allows you to then cancel that coroutine but you can't cancel (terminate) the current coroutine you are in.
Coroutine cancel error codes (get with OpenSwoole\Util::getLastErrorCode()
):
You can use OpenSwoole\Coroutine::isCanceled()
to check if a coroutine has been cancelled.
Since v4.7.0
You should not cancel the current coroutine or non-existing coroutines.