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::del(mixed $sock)\:\ bool
fd
of the socket type
If success, it returns TRUE, meaning the event listener was successfully added
Otherwise it returns FALSE, meaning there was an issue registering the event
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.
<?php
$fp = stream_socket_client("tcp://openswoole.com.com:80", $errno, $errstr, 30);
fwrite($fp,"GET / HTTP/1.1\r\nHost: openswoole.com\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);
});