src/Workers/ForkingWorker.php
private function handleChildErrors(&$socket): Closure
    {
        // This storage is freed on error (case of allowed memory exhausted).
        $reserved = str_repeat('*', 32 * 1024);

        return function () use (&$reserved, &$socket): void {
            unset($reserved);

            $error = error_get_last();

            if ($error === null) {
                unset($reserved);
                return;
            }

            $handler = new ErrorFormatter();
            if ($handler->constant($error['type']) === null) {
                $this->logger->warning(
                    '{type}: Unable to recognize error type. Skip sending error to master: {message}',
                    $this->logContext + ['message' => $error['message']]
                );
                return;
            }

            if (is_resource($socket) == false) {
                $this->logger->warning(
                    '{type}: supplied resource is not a valid socket resource. Skip sending error to master: {message}',
                    $this->logContext + ['message' => $error['message']]
                );
                return;
            }

            $this->logger->debug('{type}: sending error to master', $this->logContext);
            $data = serialize($error);

            do {
                $len = socket_write($socket, $data);
                if ($len === false || $len === 0) {
                    break;
                }

                $data = substr($data, $len);
            } while (is_numeric($len) && $len > 0 && is_resource($socket));
        };
    }
private function handleChildErrors(&$socket): Closure
    {
        // This storage is freed on error (case of allowed memory exhausted).
        $reserved = str_repeat('*', 32 * 1024);

        return function () use (&$reserved, &$socket): void {
            unset($reserved);

            $error = error_get_last();

            if ($error === null) {
                unset($reserved);
                return;
            }

            $handler = new ErrorFormatter();
            if ($handler->constant($error['type']) === null) {
                $this->logger->warning(
                    '{type}: Unable to recognize error type. Skip sending error to master: {message}',
                    $this->logContext + ['message' => $error['message']]
                );
                return;
            }

            if (is_resource($socket) == false) {
                $this->logger->warning(
                    '{type}: supplied resource is not a valid socket resource. Skip sending error to master: {message}',
                    $this->logContext + ['message' => $error['message']]
                );
                return;
            }

            $this->logger->debug('{type}: sending error to master', $this->logContext);
            $data = serialize($error);

            do {
                $len = socket_write($socket, $data);
                if ($len === false || $len === 0) {
                    break;
                }

                $data = substr($data, $len);
            } while (is_numeric($len) && $len > 0 && is_resource($socket));
        };
    }
A shutdown function for the forked process.

NOTE: Shutdown functions will not be executed if the process is killed with a SIGTERM or SIGKILL signal.

@param  resource $socket
@return Closure