Swoole\Event->isset

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


Latest version: pecl install openswoole-22.1.2

Declaration

<?php Swoole\Event::isset(mixed $fd, int $events = SWOOLE_EVENT_READ | SWOOLE_EVENT_WRITE)\:\ bool

Parameters

fd

fd of the socket type

events

SWOOLE_EVENT_READ SWOOLE_EVENT_WRITE SWOOLE_EVENT_WRITE|SWOOLE_EVENT_READ

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

Check if the given fd is registered on the Event Loop with the passed in event type.

Event Types To Check

  • SWOOLE_EVENT_READ: Check to see if the event is listening for readable events
  • SWOOLE_EVENT_WRITE: Check to see if the event is listening for writeable events
  • SWOOLE_EVENT_READ | SWOOLE_EVENT_WRITE: Check to see if the event is listening for readable and or writeable events

Example

<?php
use Swoole\Event;

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

Event::add($fp, function($fp) {

    $resp = fread($fp, 8192);
    Swoole\Event::del($fp);
    fclose($fp);

}, null, SWOOLE_EVENT_READ);

var_dump(Event::isset($fp, SWOOLE_EVENT_READ)); // true
var_dump(Event::isset($fp, SWOOLE_EVENT_WRITE)); // false
var_dump(Event::isset($fp, SWOOLE_EVENT_READ | SWOOLE_EVENT_WRITE)); // true
Last updated on August 31, 2022