OpenSwoole\Event::del

Latest version: pecl install openswoole-22.1.2 | composer require openswoole/core:22.1.5

Declaration

<?php OpenSwoole\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...
OpenSwoole\Event::add($fp, function($fp) {

    $resp = fread($fp, 8192);

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

});
Last updated on September 1, 2022