OpenSwoole\Event->isset

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

Declaration

<?php OpenSwoole\Event::isset(mixed $fd, int $events = OpenSwoole\Constant::EVENT_READ | OpenSwoole\Constant::EVENT_WRITE)\:\ bool

Parameters

fd

fd of the socket type

events

OpenSwoole\Constant::EVENT_READ OpenSwoole\Constant::EVENT_WRITE OpenSwoole\Constant::EVENT_WRITE|OpenSwoole\Constant::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

  • OpenSwoole\Constant::EVENT_READ: Check to see if the event is listening for readable events
  • OpenSwoole\Constant::EVENT_WRITE: Check to see if the event is listening for writeable events
  • OpenSwoole\Constant::EVENT_READ | OpenSwoole\Constant::EVENT_WRITE: Check to see if the event is listening for readable and or writeable events

Example

<?php
use OpenSwoole\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);
    OpenSwoole\Event::del($fp);
    fclose($fp);

}, null, OpenSwoole\Constant::EVENT_READ);

var_dump(Event::isset($fp, OpenSwoole\Constant::EVENT_READ)); // true
var_dump(Event::isset($fp, OpenSwoole\Constant::EVENT_WRITE)); // false
var_dump(Event::isset($fp, OpenSwoole\Constant::EVENT_READ | OpenSwoole\Constant::EVENT_WRITE)); // true
Last updated on September 20, 2022