Join 4,000+ others and never miss out on new tips, tutorials, and more.
Latest version:
pecl install openswoole-22.1.2 | composer require openswoole/core:22.1.5
<?php OpenSwoole\Event::isset(mixed $fd, int $events = OpenSwoole\Constant::EVENT_READ | OpenSwoole\Constant::EVENT_WRITE)\:\ bool
fd
of the socket type
OpenSwoole\Constant::EVENT_READ
OpenSwoole\Constant::EVENT_WRITE
OpenSwoole\Constant::EVENT_WRITE|OpenSwoole\Constant::EVENT_READ
If success, it returns TRUE, meaning the event listener was successfully added
Otherwise it returns FALSE, meaning there was an issue registering the event
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 eventsOpenSwoole\Constant::EVENT_WRITE
: Check to see if the event is listening for writeable eventsOpenSwoole\Constant::EVENT_READ | OpenSwoole\Constant::EVENT_WRITE
: Check to see if the event is listening for readable and or writeable events<?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