Swoole\Event::del

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

false

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://www.swoole.co.uk.com:80", $errno, $errstr, 30);
fwrite($fp,"GET / HTTP/1.1\r\nHost: www.swoole.co.uk\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);

});