Join 4,000+ others and never miss out on new tips, tutorials, and more.
4.x is outdated, please check the latest version 22.x
Latest version:
pecl install openswoole-22.1.2
<?php Swoole\Event::isset(mixed $fd, int $events = SWOOLE_EVENT_READ | SWOOLE_EVENT_WRITE)\:\ bool
fd
of the socket type
SWOOLE_EVENT_READ
SWOOLE_EVENT_WRITE
SWOOLE_EVENT_WRITE|SWOOLE_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
SWOOLE_EVENT_READ
: Check to see if the event is listening for readable eventsSWOOLE_EVENT_WRITE
: Check to see if the event is listening for writeable eventsSWOOLE_EVENT_READ | SWOOLE_EVENT_WRITE
: Check to see if the event is listening for readable and or writeable events<?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