Swoole Server finish

4.x is outdated, please check the latest version 22.x


Latest version: pecl install openswoole-22.1.2

Declaration

<?php Swoole\Server->finish(mixed $data)

Parameters

data

The data can be any valid PHP type you want to send back to the worker process once the task has completed. The data here acts as the result of the task to send back to the worker process.

Return

success

If successful, the data that is passed in is returned to the worker process

Description

Used in task process for sending result to the worker process when the task is finished.

Once a task is deem complete you can send back any resulting data to the worker process and its registered onFinish callback event, the onFinish event is used to process result data from any completed tasks. Inside a task process, once it has completed you may use Swoole\Server->finish to send back data to the worker process and handle any results from what was done inside the task worker process.

This method can be thought of as a way to notify the worker process that the task completed and here are the results but if the worker process does not need to process any resulting data, you are not required to use this method or return any data from a task process.

You may call this method or return task data multiple times, this will then result in the onFinish event being triggered multiple times.

You must only use this function within a task process and have your onFinish event registered.

Last updated on August 31, 2022