Swoole\Event::del

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


Latest version: pecl install openswoole-22.1.2

Declaration

<?php Swoole\Event::del(mixed $sock)\:\ bool

Parameters

fd

fd of the socket type

Return

success

If success, it returns TRUE, meaning the event listener was successfully added

Otherwise it returns FALSE, meaning there was an issue registering the event

Description

Remove a read and write callback function and any flags registered on the Event Loop for the given file descriptor. No longer monitor any read or write events. Usually used inside of Event::add when you want to perform other operations on the socket. Make sure to close your fd after using this method otherwise, it could cause a memory leak.

Example

<?php

$fp = stream_socket_client("tcp://openswoole.com.com:80", $errno, $errstr, 30);
fwrite($fp,"GET / HTTP/1.1\r\nHost: openswoole.com\r\n\r\n");

// Register new event...
Swoole\Event::add($fp, function($fp) {

    $resp = fread($fp, 8192);

    // Remove the socket from event loop
    Swoole\Event::del($fp);
    fclose($fp);

});
Last updated on August 31, 2022